www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Another variant bug? problem? misleading feature?

The following program crash with the following error:
----
std.variant.VariantException std\variant.d(1161): Attempt to use an 
uninitialized VariantN
----
========
module main;

import std.variant;
import std.stdio;

class Foo
{
}

int main(string[] argv)
{
    Variant v1 = Variant.init;
    writeln(v1.convertsTo!Foo);

    return 0;
}
========
Why would a test method, which test if the value can be used thrown an 
error?
Why simply not return false if the variant is uninitialized?

Anyway I found a work around
----
writeln(v1 != Variant.init && v1.convertsTo!Foo);
----
Jun 24 2011