typesdtype-conversionphobos

What is the right way to convert Variant to proper type?


I use mysql-native that return Variant data type. I need to convert it to standard types like int, string etc.

D have std.conv, but std.variant also have methods for concretion.

I can't understand what difference between: get, coerce, toString and to (from std.conv).

Also it's sound very strange that convertsTo is return bool. By it's name I expected that it should do convention. IMHO isConvertable is more proper name for it.


Solution

  • There are three ways to get the value from a Variant type: