On 02/08/2016 07:49 PM, Enjoys Math wrote:
This:
         double b = 1.0;

     Variant[string] aa = ["b": &b];

     writeln(aa["b"]);

fails with:

Error: cannot implicitly convert expression(["b":&b]) of type
double*[string] to VariantN!20u[string]

Helps please!

When initializing the array, you have to use Variant(&b):

import std.stdio;
import std.variant;

void main() {
    double b = 1.5;

    Variant[string] aa = ["b": Variant(&b)];

    writeln(aa);
    writeln(aa["b"]);
    writeln(*aa["b"].get!(double*));
}

Prints something like the following:

["b":7FFD0104B100]
7FFD0104B100
1.5

Ali

Reply via email to