User defined constructors now can construct all default types (e.g. float).
This commit is contained in:
parent
edf3e2a799
commit
c7e97b6113
|
@ -369,7 +369,7 @@ final class Constructor
|
|||
|
||||
return (ref Node n)
|
||||
{
|
||||
static if(Node.Value.allowed!T){return Node.Value(ctor(n));}
|
||||
static if(Node.allowed!T){return Node.value(ctor(n));}
|
||||
else {return Node.userValue(ctor(n));}
|
||||
};
|
||||
}
|
||||
|
|
22
dyaml/node.d
22
dyaml/node.d
|
@ -1336,6 +1336,28 @@ struct Node
|
|||
return Value(cast(YAMLObject)new YAMLContainer!T(value));
|
||||
}
|
||||
|
||||
//Construct Node.Value from a type it can store directly (after casting if needed)
|
||||
static Value value(T)(T value) @trusted if(allowed!T)
|
||||
{
|
||||
static if(Value.allowed!T)
|
||||
{
|
||||
return Value(value);
|
||||
}
|
||||
else static if(isIntegral!T)
|
||||
{
|
||||
return Value(cast(long)(value));
|
||||
}
|
||||
else static if(isFloatingPoint!T)
|
||||
{
|
||||
return Value(cast(real)(value));
|
||||
}
|
||||
else static if(isSomeString!T)
|
||||
{
|
||||
return Value(to!string(value));
|
||||
}
|
||||
else static assert(false, "Unknown value type. Is value() in sync with allowed()?");
|
||||
}
|
||||
|
||||
/*
|
||||
* Equality test with any value.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue