Re: Nullable with reference types

2015-07-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 30, 2015 14:29:52 Steven Schveighoffer via Digitalmars-d-learn wrote: I know this is just back-of-envelope, but what's wrong with: alias Nullable(T) if(is(T == class)) = T; bool isNull(T)(T t) if(is(T == class)) { return t is null;} In principle, there's no reason why we

Re: Nullable with reference types

2015-07-01 Thread via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 18:29:31 UTC, Steven Schveighoffer wrote: I know this is just back-of-envelope, but what's wrong with: alias Nullable(T) if(is(T == class)) = T; bool isNull(T)(T t) if(is(T == class)) { return t is null;} That's what I intended. (Same for pointers and slices,

Re: Nullable with reference types

2015-07-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/1/15 5:45 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Tuesday, 30 June 2015 at 18:29:31 UTC, Steven Schveighoffer wrote: I know this is just back-of-envelope, but what's wrong with: alias Nullable(T) if(is(T == class)) = T; bool isNull(T)(T t) if(is(T == class)) { return

Re: Nullable with reference types

2015-07-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/1/15 5:45 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Tuesday, 30 June 2015 at 18:29:31 UTC, Steven Schveighoffer wrote: I know this is just back-of-envelope, but what's wrong with: alias Nullable(T) if(is(T == class)) = T; bool isNull(T)(T t) if(is(T == class)) { return

Re: Nullable with reference types

2015-07-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, July 01, 2015 08:43:59 Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/1/15 5:45 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Tuesday, 30 June 2015 at 18:29:31 UTC, Steven Schveighoffer wrote: I know this is just back-of-envelope, but what's wrong with:

Re: Nullable with reference types

2015-06-30 Thread Meta via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:17:00 UTC, Jonathan M Davis wrote: I tend to think that it's incredibly stupid to use something like Nullable for a type that's already Nullable. Unfortunately, we're stuck with it as changing that would break code. It's just silly. If a type is already

Re: Nullable with reference types

2015-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g.

Re: Nullable with reference types

2015-06-30 Thread via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: It's a design mistake in Nullable. I would suggest that either never use Nullable with a type that already has a null value, or use the overload of Nullable that takes a null value, and set it to null. Example: Class Test {} alias

Re: Nullable with reference types

2015-06-30 Thread Meta via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 11:50:19 UTC, Marc Schütz wrote: On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: It's a design mistake in Nullable. I would suggest that either never use Nullable with a type that already has a null value, or use the overload of Nullable that takes a null

Re: Nullable with reference types

2015-06-30 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)? P.S. I have experience with C#, where `NullableT`

Re: Nullable with reference types

2015-06-30 Thread Meta via Digitalmars-d-learn
On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)? P.S. I have experience with C#, where `NullableT`

Nullable with reference types

2015-06-30 Thread sigod via Digitalmars-d-learn
Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)? P.S. I have experience with C#, where `NullableT` cannot be used with reference types. And it sounds

Re: Nullable with reference types

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 11:16 AM, Jonathan M Davis wrote: On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed