Re: Nullable instantiator anyone?

2014-08-18 Thread Nordlöw
On Monday, 18 August 2014 at 01:22:00 UTC, Ali Çehreli wrote: The following solution relies on an alias template parameter and a template constraint. The code covers both Nullable variants: import std.typecons; auto nullable(T)(T value) { return Nullable!T(value); } unittest { auto x

Re: Nullable instantiator anyone?

2014-08-17 Thread Phil Lavoie via Digitalmars-d-learn
On Sunday, 17 August 2014 at 19:05:11 UTC, Nordlöw wrote: On Sunday, 17 August 2014 at 18:51:38 UTC, bearophile wrote: It could be sufficient, but note that in Phobos there are two different versions of Nullable, one of them doesn't require extra memory, it uses one value as the "null" value.

Re: Nullable instantiator anyone?

2014-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 08/17/2014 12:05 PM, "Nordlöw" wrote: > On Sunday, 17 August 2014 at 18:51:38 UTC, bearophile wrote: >> It could be sufficient, but note that in Phobos there are two >> different versions of Nullable, one of them doesn't require extra >> memory, it uses one value as the "null" value. > > Ok, t

Re: Nullable instantiator anyone?

2014-08-17 Thread Nordlöw
On Sunday, 17 August 2014 at 18:51:38 UTC, bearophile wrote: It could be sufficient, but note that in Phobos there are two different versions of Nullable, one of them doesn't require extra memory, it uses one value as the "null" value. Ok, thanks for the reminder. Do you have a suggestion of

Re: Nullable instantiator anyone?

2014-08-17 Thread bearophile via Digitalmars-d-learn
Nordlöw: I'm missing an instantiator function for std.typecons:Nullable. Is this is intentional? If not, is this Nullable!T nullable(T)(T a) { return typeof(return)(a); } sufficient for our needs? It could be sufficient, but note that in Phobos there are two different versions of Nulla

Nullable instantiator anyone?

2014-08-17 Thread Nordlöw
I'm missing an instantiator function for std.typecons:Nullable. Is this is intentional? If not, is this Nullable!T nullable(T)(T a) { return typeof(return)(a); } sufficient for our needs?