NULL indicator in Variant

Steve Teale steve.teale at britseyeview.com
Thu Oct 27 10:53:02 PDT 2011


On Thu, 27 Oct 2011 13:09:43 -0400, Steven Schveighoffer wrote:

> On Thu, 27 Oct 2011 12:58:57 -0400, Steve Teale
> <steve.teale at britseyeview.com> wrote:
> 
>> On Thu, 27 Oct 2011 16:16:26 +0200, Alex Rønne Petersen wrote:
>>
>>> On 27-10-2011 15:50, Steve Teale wrote:
>>>>>
>>>>> Surely Variant.init should do the trick?
>>>>
>>>> Dmitry,
>>>>
>>>> Are you talking about the new std.variant - I don't see 'init'
>>>> currently.
>>>>
>>>> Steve
>>>
>>> He is probably referring to the 'init' property on the *type*, i.e.
>>> int.init and so on.
>>>
>>> - Alex
>>
>> Same catch 22. In order to have an init property, the Variant would
>> have to have been set to some type, at which point hasValue() would say
>> yes.
>>
>> Steve
> 
> import std.variant;
> 
> void main()
> {
>      Variant v = 1;
>      assert(v.hasValue());
>      v = v.init;
>      assert(!v.hasValue());
> }
> 
> -Steve

Exactly, and v has reverted to being typeless:

import std.variant;
import std.stdio;

void main()
{
     Variant v = 1;
     assert(v.hasValue());
     v = v.init;
     assert(!v.hasValue());
     writeln(v.type.toString());
}

Steve


More information about the Digitalmars-d mailing list