Re: Is there a simple way to check if value is null for every case?

2018-08-26 Thread rikki cattermole via Digitalmars-d-learn
On 27/08/2018 12:51 PM, SG wrote: On Sunday, 26 August 2018 at 16:39:53 UTC, rikki cattermole wrote: UFCS function called isNull. e.g. import std.traits : isPointer; bool isNull(T)(T value) if (is(T == class) || isPointer!T) { return value is null; } Hi Rikki, I'm still confused, I

Re: Is there a simple way to check if value is null for every case?

2018-08-26 Thread SG via Digitalmars-d-learn
On Sunday, 26 August 2018 at 16:39:53 UTC, rikki cattermole wrote: UFCS function called isNull. e.g. import std.traits : isPointer; bool isNull(T)(T value) if (is(T == class) || isPointer!T) { return value is null; } Hi Rikki, I'm still confused, I want to create a extension for

Re: Can passing an address of this to a non-copyable object be made trusted? - i.e. can I disable moving?

2018-08-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 26, 2018 5:10:29 PM MDT Nicholas Wilson via Digitalmars-d- learn wrote: > On Sunday, 26 August 2018 at 20:17:30 UTC, aliak wrote: > > So if we had this: > > > > struct A(T) { > > > > auto proxy() @trusted { > > > > return B!T(); > > > > } > > > > } > > > > struct B(T) { >

Re: Can passing an address of this to a non-copyable object be made trusted? - i.e. can I disable moving?

2018-08-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 26 August 2018 at 20:17:30 UTC, aliak wrote: So if we had this: struct A(T) { auto proxy() @trusted { return B!T(); } } struct B(T) { private A!T* source; private this(A!T* s) { source = s; } @disable this(); @disable this(this) {} @disable void opAssign(B!T); }

Can passing an address of this to a non-copyable object be made trusted? - i.e. can I disable moving?

2018-08-26 Thread aliak via Digitalmars-d-learn
So if we had this: struct A(T) { auto proxy() @trusted { return B!T(); } } struct B(T) { private A!T* source; private this(A!T* s) { source = s; } @disable this(); @disable this(this) {} @disable void opAssign(B!T); } In order for f to be "safe" I need to ensure that B!T()

Re: Patterns to avoid GC with capturing closures?

2018-08-26 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 26 August 2018 at 06:08:39 UTC, vit wrote: const x = iota(0, 10) .map!((x, i) => x*i)(a) ///map!((x) => x*a) .map!((x, i) => x*i)(b) ///map!((x) => x*b) .filter!((x, i) => x%i)(c)///filter!((x) => x%c) .any!(x => x % c); I think it's easier to

Is there a simple way to check if value is null for every case?

2018-08-26 Thread SG via Digitalmars-d-learn
Hi again, The code below works for some cases but not for the Nullable!Type. A way to fix it should be check the type and use ".isNull" for Nullabe!Type. But is there a simple way to test if value is null for every case? import std.stdio, std.typecons, std.variant, std.conv; bool foo(T)(T

Re: Is there a simple way to check if value is null for every case?

2018-08-26 Thread rikki cattermole via Digitalmars-d-learn
On 27/08/2018 4:37 AM, SG wrote: Hi again, The code below works for some cases but not for the Nullable!Type. A way to fix it should be check the type and use ".isNull" for Nullabe!Type. But is there a simple way to test if value is null for every case? import std.stdio, std.typecons,

Re: Patterns to avoid GC with capturing closures?

2018-08-26 Thread aliak via Digitalmars-d-learn
On Friday, 24 August 2018 at 22:51:40 UTC, Paul Backus wrote: On Friday, 24 August 2018 at 15:18:13 UTC, Peter Alexander wrote: I can write scaleAll like this: auto scaleAll(int[] xs, int m) @nogc { return repeat(m).zip(xs).map!(mx => mx[0] * mx[1]); } So that repeat(m) stores m, but it is

Re: Patterns to avoid GC with capturing closures?

2018-08-26 Thread vit via Digitalmars-d-learn
On Friday, 24 August 2018 at 15:18:13 UTC, Peter Alexander wrote: Consider this code, which is used as an example only: auto scaleAll(int[] xs, int m) { return xs.map!(x => m * x); } As m is captured, the delegate for map will rightly allocate the closure in the GC heap. In C++, you would