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

2018-08-28 Thread aliak via Digitalmars-d-learn
On Monday, 27 August 2018 at 21:48:04 UTC, Alex wrote: On Monday, 27 August 2018 at 19:36:29 UTC, aliak wrote: Then Nullable!(int*) would be the same as int*. Or even better maybe is to give a compiler error when you try and stuff a nullable type inside a Nullable. Because ... why? Isn't

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

2018-08-27 Thread Alex via Digitalmars-d-learn
On Monday, 27 August 2018 at 19:36:29 UTC, aliak wrote: Then Nullable!(int*) would be the same as int*. Or even better maybe is to give a compiler error when you try and stuff a nullable type inside a Nullable. Because ... why? Isn't it arguable, whether this is desired? I mean, in the

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

2018-08-27 Thread aliak via Digitalmars-d-learn
On Monday, 27 August 2018 at 14:11:32 UTC, SG wrote: On Monday, 27 August 2018 at 13:02:28 UTC, rikki cattermole wrote: So Nullable in D and C# is basically the same except C#'s has language support. The big difference is that in there I could do: int? i = null; string j = null; var

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

2018-08-27 Thread Jacob Shtokolov via Digitalmars-d-learn
On Monday, 27 August 2018 at 14:11:32 UTC, SG wrote: On Monday, 27 August 2018 at 13:02:28 UTC, rikki cattermole wrote: So Nullable in D and C# is basically the same except C#'s has language support. Shouldn't it be in the standard library? I think it's worth it to create a feature request

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

2018-08-27 Thread SG via Digitalmars-d-learn
On Monday, 27 August 2018 at 13:02:28 UTC, rikki cattermole wrote: So Nullable in D and C# is basically the same except C#'s has language support. The big difference is that in there I could do: int? i = null; string j = null; var k = null; and test all like: i == null; j

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

2018-08-27 Thread vit via Digitalmars-d-learn
On Monday, 27 August 2018 at 12:54:59 UTC, SG wrote: On Monday, 27 August 2018 at 03:21:04 UTC, rikki cattermole wrote: Templates make it the easiest way, since common patterns, like arrays, classes and pointers have the exact same null check syntax. I see. That code is only for classes. C#

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

2018-08-27 Thread rikki cattermole via Digitalmars-d-learn
On 28/08/2018 12:54 AM, SG wrote: The same thing for struct in C# Struct S{    public int? i; } S.i == null; // This works nicely. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/index So Nullable in D and C# is basically the same except C#'s has language

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

2018-08-27 Thread SG via Digitalmars-d-learn
On Monday, 27 August 2018 at 03:21:04 UTC, rikki cattermole wrote: Templates make it the easiest way, since common patterns, like arrays, classes and pointers have the exact same null check syntax. I see. That code is only for classes. C# also has structs which are a value type. Which it

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

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,