Re: Remove closure allocation

2018-05-26 Thread Neia Neutuladh via Digitalmars-d-learn
On Saturday, 26 May 2018 at 15:00:40 UTC, Malte wrote: This compiles with DMD, however it returns random numbers instead of the value I passed in. Looks like a bug to me. Should that work or is there any other pattern I could use for that? Filed as

Re: convert string to wchar[]

2018-05-26 Thread Neia Neutuladh via Digitalmars-d-learn
On Saturday, 26 May 2018 at 17:12:38 UTC, Dr.No wrote: What's D's way to do that? I need it to be mutable array of wchar because a Windows function requires that. Alternative to go down to using pointers, which would be something like: wchar[] w = new wchar[s.length]; memcpy(w.ptr, s.ptr,

convert string to wchar[]

2018-05-26 Thread Dr.No via Digitalmars-d-learn
What's D's way to do that? I need it to be mutable array of wchar because a Windows function requires that. Alternative to go down to using pointers, which would be something like: wchar[] w = new wchar[s.length]; memcpy(w.ptr, s.ptr, s.length);

Remove closure allocation

2018-05-26 Thread Malte via Digitalmars-d-learn
I was trying to get a function that has a closure allocation to compile with @nogc. Assuming this function: int identity(immutable int q) pure nothrow @safe { import std.algorithm; static immutable auto arr = [42]; int getSecondArgument(int a, int b) { return b; }

Re: Translate C/C++ patern: return a pointer

2018-05-26 Thread biocyberman via Digitalmars-d-learn
On Thursday, 24 May 2018 at 17:44:19 UTC, Jacob Carlborg wrote: On 2018-05-24 11:10, biocyberman wrote: Thanks for the hints. `Read` in C++ and D are both classes. And the function is inside the class definition itself. In that case specifying the type as `Read` is the correct thing to do.