Nullable or Optional? Or something else?

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Sep 2 17:54:46 PDT 2009


On Wed, Sep 2, 2009 at 8:20 PM, Jeremie Pelletier<jeremiep at gmail.com> wrote:
> Andrei Alexandrescu Wrote:
>
>> 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?
>>
>>
>> Andrei
>
>
> I just recently converted tons of COM headers in win32 to D (gotta love extern(C++)) and I really like how they hint the compiler of what parameters are used for. They have all sorts of macros like __in, __inout, __out, __in_opt, __inout_opt, __out_opt.
>
> Why can't these be used in D too and implicitly add the appropriate contracts to the function:
>
> void foo(in_opt int* a) { ... }
>
> can be the same as
>
> void foo(in int* a)
> in { assert(a); }
> body { ... }
>
> I know I'm trying to push a lot of library stuff to the language spec, but it would just be so much more convenient that way. in_opt would be semantically the same as in, with the added contract.

Hmm, you know this could be handled raaaaaather niiiiicely with attributes.

void foo(@in_opt int* a) { ... }

But they don't have any compelling use cases, right?







they just keep showing up, huh



More information about the Digitalmars-d mailing list