Re: How to specify a template that uses unqualified type, like any normal function

2017-08-16 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 14:24:57 UTC, Steven Schveighoffer wrote: What IFTI would need is a mechanism to change the parameter types to mutable similar to how you can do this: foo(T)(const(T) t); This now generates one function for int, const(int), immutable(int), and t is const within

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread crimaniak via Digitalmars-d-learn
On Monday, 14 August 2017 at 03:59:48 UTC, Jonathan M Davis wrote: The way to handle shared is to protect the section of code that's using the shared object with either a mutex or synchronized block, and then you cast away shared from the object within that section and operate on it as thread-

Re: Automatic function body writing howto?

2017-08-16 Thread Meta via Digitalmars-d-learn
It's hard to tell offhand but I would recommend that you extract the inner string into a function that generates that string, allowing you to print out the finished product before mixing it in.

Automatic function body writing howto?

2017-08-16 Thread Oleg B via Digitalmars-d-learn
I want declare only signature of function and build body code by CTFE. module mdl; import std.stdio; import std.traits; import std.string; enum autofnc; @autofnc { int foo(int); int bar(int); } void main() { writeln(foo(12)); } mixin cfuncR; mixin template cfuncR() {

In DUB, how do I conditionally compile code based on optional dependencies?

2017-08-16 Thread Daniel Kozak via Digitalmars-d-learn
There is a question on SO: https://stackoverflow.com/questions/45697469/in-dub-how-do-i-conditionally-compile-code-based-on-optional-dependencies I have found the answer, but I am interesting is there any doc about this?

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Arek via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 21:54:23 UTC, Steven Schveighoffer wrote: On 8/15/17 5:27 PM, Arek wrote: On Tuesday, 15 August 2017 at 10:37:08 UTC, Kagamin wrote: Well, no wrapper is actually needed here: [...] The issue is that send cannot handle shared value types due to a bug in the imple

Re: struct field initialization

2017-08-16 Thread bitwise via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 18:17:36 UTC, kinke wrote: On Wednesday, 16 August 2017 at 18:11:05 UTC, bitwise wrote: If I define a non-default constructor for a struct, are the fields initialized to T.init by the time it's called? The struct instance is initialized with T.init before invoki

Re: How to fix wrong deprecation message - dmd-2.075.1

2017-08-16 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 16:54:04 UTC, Pham wrote: On Wednesday, 16 August 2017 at 13:55:31 UTC, Steven Schveighoffer wrote: On 8/16/17 9:12 AM, Daniel Kozak via Digitalmars-d-learn wrote: It should not be print? AIAIK std.utf.toUTF16 is not deprecated: http://dlang.org/phobos/std_utf.ht

Re: struct field initialization

2017-08-16 Thread bitwise via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 18:11:05 UTC, bitwise wrote: [...] I'm asking this because I need to forward args to a container's node's value. Something like this: struct Node(T) { int flags; T value; // maybe const this(Args...)(int flags, auto ref Args args) {

Re: struct field initialization

2017-08-16 Thread kinke via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 18:11:05 UTC, bitwise wrote: If I define a non-default constructor for a struct, are the fields initialized to T.init by the time it's called? The struct instance is initialized with T.init before invoking the constructor.

struct field initialization

2017-08-16 Thread bitwise via Digitalmars-d-learn
If I define a non-default constructor for a struct, are the fields initialized to T.init by the time it's called? or am I responsible for initializing all fields in that constructor? ..or do structs follow the same rules as classes? https://dlang.org/spec/class.html#field-init Thanks

Re: Formated Output and file creation time

2017-08-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 16, 2017 at 03:30:18PM +, Vino.B via Digitalmars-d-learn wrote: [...] > Current Output > C:\Test1\Test2\T.txt 1234 2017-Aug-16 19:10:54.0618385 > C:\Test1\Test2\TX.txt 1234 2017-Aug-16 19:10:54.0618385 > C:\Test1\Test2\TXXX.txt 1234 2017-Aug-16 19:10:54.06183

Re: How to fix wrong deprecation message - dmd-2.075.1

2017-08-16 Thread Pham via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 13:55:31 UTC, Steven Schveighoffer wrote: On 8/16/17 9:12 AM, Daniel Kozak via Digitalmars-d-learn wrote: It should not be print? AIAIK std.utf.toUTF16 is not deprecated: http://dlang.org/phobos/std_utf.html#toUTF16 OK this one is:https://github.com/dlang/phobo

Formated Output and file creation time

2017-08-16 Thread Vino.B via Digitalmars-d-learn
Hi, I have a small program which will list the file names, size and creation date and time, the output of the program is as below and required your help to print the output as per "Required Output" Current Output C:\Test1\Test2\T.txt 1234 2017-Aug-16 19:10:54.0618385 C:\Tes

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/17 8:58 AM, Steven Schveighoffer wrote: However, I have found a better way to call postblit that involves the qualifiers than the way Variant currently does it. I'm going to submit a PR to fix these issues. https://github.com/dlang/phobos/pull/5694 -Steve

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/17 10:32 AM, Suliman wrote: On Wednesday, 16 August 2017 at 13:41:29 UTC, Biotronic wrote: On Wednesday, 16 August 2017 at 12:50:07 UTC, Suliman wrote: MyStruct[] is actually a struct similar to this: struct MyStruct[] { MyStruct* ptr; size_t length; } That struct is placed on

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Suliman via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 13:41:29 UTC, Biotronic wrote: On Wednesday, 16 August 2017 at 12:50:07 UTC, Suliman wrote: MyStruct[] is actually a struct similar to this: struct MyStruct[] { MyStruct* ptr; size_t length; } That struct is placed on the stack, but the data it points t

Re: How to fix wrong deprecation message - dmd-2.075.1

2017-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/17 9:12 AM, Daniel Kozak via Digitalmars-d-learn wrote: It should not be print? AIAIK std.utf.toUTF16 is not deprecated: http://dlang.org/phobos/std_utf.html#toUTF16 OK this one is:https://github.com/dlang/phobos/blob/v2.075.1/std/utf.d#L2760 (but this one is not in doc) but this on

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 12:50:07 UTC, Suliman wrote: MyStruct[] is actually a struct similar to this: struct MyStruct[] { MyStruct* ptr; size_t length; } That struct is placed on the stack, but the data it points to, via the ptr field, is heap allocated. What is struct? Just

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/17 9:04 AM, Kagamin wrote: On Wednesday, 16 August 2017 at 12:58:25 UTC, Steven Schveighoffer wrote: Use cases don't matter. What matters is: is it proper for Variant to call the postblit (as it does currently) without regard for the qualifiers? Looks like it isn't, https://dpaste.dzf

Re: How to fix wrong deprecation message - dmd-2.075.1

2017-08-16 Thread Daniel Kozak via Digitalmars-d-learn
It should not be print? AIAIK std.utf.toUTF16 is not deprecated: http://dlang.org/phobos/std_utf.html#toUTF16 OK this one is:https://github.com/dlang/phobos/blob/v2.075.1/std/utf.d#L2760 (but this one is not in doc) but this one should not be deprecated: https://github.com/dlang/phobos/blob/v2.07

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 12:58:25 UTC, Steven Schveighoffer wrote: Use cases don't matter. What matters is: is it proper for Variant to call the postblit (as it does currently) without regard for the qualifiers? Looks like it isn't, https://dpaste.dzfl.pl/183e6dae9867 - shared referenc

Re: How to fix wrong deprecation message - dmd-2.075.1

2017-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/17 1:09 AM, apz28 wrote: void main() { import std.utf : toUTF16; // Same problem with toUTF8 wstring s = toUTF16!string("abc"); } Compilation output: /d500/f513.d(3): Deprecation: function std.utf.toUTF16 is deprecated - To be removed November 2017. Please use std.utf.encode

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/17 6:23 AM, Kagamin wrote: On Tuesday, 15 August 2017 at 15:19:02 UTC, Steven Schveighoffer wrote: However, I'm not sure about the postblit being called afterward. Does a postblit need to be marked shared in order to work for shared types? Ideally yes, but it's difficult to come up wit

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Suliman via Digitalmars-d-learn
MyStruct[] is actually a struct similar to this: struct MyStruct[] { MyStruct* ptr; size_t length; } That struct is placed on the stack, but the data it points to, via the ptr field, is heap allocated. What is struct? Just name and size?

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 15:19:02 UTC, Steven Schveighoffer wrote: However, I'm not sure about the postblit being called afterward. Does a postblit need to be marked shared in order to work for shared types? Ideally yes, but it's difficult to come up with a good shared postblit, send and

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 21:27:49 UTC, Arek wrote: Yes, but this doesn't compile: import std.stdio; import std.concurrency; struct A { int t; int r; int method() shared { return 0; } } void consumer() { shared a = receiveOnly

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 07:39:01 UTC, Suliman wrote: On the heap, unless you are allocating it via e.g. alloca. If struct MyStruct { int x; int y; } MyStruct mystruct; is located on stack, why: MyStruct [] mystructs; should located on heap? MyStruct[] is actually a struct simila

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 07:39:01 UTC, Suliman wrote: On the heap, unless you are allocating it via e.g. alloca. If struct MyStruct { int x; int y; } MyStruct mystruct; is located on stack, why: MyStruct [] mystructs; should located on heap? because in D MyStruct [] mystructs;

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Suliman via Digitalmars-d-learn
On the heap, unless you are allocating it via e.g. alloca. If struct MyStruct { int x; int y; } MyStruct mystruct; is located on stack, why: MyStruct [] mystructs; should located on heap?

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread rikki cattermole via Digitalmars-d-learn
On 16/08/2017 8:14 AM, Suliman wrote: On Wednesday, 16 August 2017 at 07:09:02 UTC, rikki cattermole wrote: On 16/08/2017 8:06 AM, Suliman wrote: If structures placing data on the stack why we do not getting stackoveflow while we creating array of structures? Or for example big structure. Am

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Suliman via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 07:09:02 UTC, rikki cattermole wrote: On 16/08/2017 8:06 AM, Suliman wrote: If structures placing data on the stack why we do not getting stackoveflow while we creating array of structures? Or for example big structure. Am I right understand that structures pla

If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Suliman via Digitalmars-d-learn
If structures placing data on the stack why we do not getting stackoveflow while we creating array of structures? Or for example big structure. Am I right understand that structures placing data _only_ on stack? But the stack size is very limited (on Widnows it's just 1MB). So how it's work

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread rikki cattermole via Digitalmars-d-learn
On 16/08/2017 8:06 AM, Suliman wrote: If structures placing data on the stack why we do not getting stackoveflow while we creating array of structures? Or for example big structure. Am I right understand that structures placing data _only_ on stack? But the stack size is very limited (on Widn