Nullable or Optional? Or something else?
Leandro Lucarella
llucax at gmail.com
Thu Sep 3 08:48:03 PDT 2009
Andrei Alexandrescu, el 3 de septiembre a las 10:34 me escribiste:
> Leandro Lucarella wrote:
> >Andrei Alexandrescu, el 2 de septiembre a las 14:39 me escribiste:
> >>I plan to add a Nullable struct to Phobos (akin to C#'s Nullable, Boost's Optional).
> >>
> >>Apparently a good design is to define Optional!T with a minimum of member functions (ideally none) and have it use the "alias this" feature to masquerade as
> >>a T. That way Optional!T looks and feels much like a T, except that it supports a function
> >>
> >>bool isNull(T)(Optional!T value);
> >>
> >>Am I on the right track? If so, what is the name you'd prefer for this artifact?
> >Maybe this is a very silly question, but what is exactly the difference
> >between Optional!T o/isNull(o) and T* o/o is null?
>
> It's a good question. There are two differences: (a) Optional!T behaves
> almost like a T in expressions, and (b) Optional!T does not support most
> features of pointers, such as arithmetic and comparison.
(a) And *o behaves *exactly* like T, that doesn't seems like an advantage
So, judging for (b) I guess is just a safety meassure.
I agree with some other mail in this thread that it would be better to
have proper references if you don't want to allow pointer arithmetics...
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Hey you, dont help them to bury the light
Don't give in without a fight.
More information about the Digitalmars-d
mailing list