Nullable!T with T of class type

Nathan S. no.public.email at example.com
Tue Jun 26 14:32:59 UTC 2018


On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote:
> Is it possible
> to "lower" the Nullable operations if T is a class type such 
> that there
> is only one level of nullification?

Yes: https://run.dlang.io/is/hPxbyf

----
template Nullable(S)
{
     import std.traits : isPointer, isDynamicArray;
     static if (is(S == class) || is(S == interface)
                || is(S == function) || is(S == delegate)
                || isPointer!S || isDynamicArray!S)
     {
         alias Nullable = S;
     }
     else
     {
         static import std.typecons;
         alias Nullable = std.typecons.Nullable!S;
     }
}
----



More information about the Digitalmars-d-learn mailing list