Scripting with Variant from std.variant: parameter passing

Danilo codedan at aol.com
Fri Feb 2 10:55:57 UTC 2024


On Friday, 2 February 2024 at 08:22:42 UTC, Carl Sturtivant wrote:
> It seems I cannot pass e.g. an int argument to a Variant 
> function parameter. What's the simplest way to work around this 
> restriction?

Just tell the compiler clearly what you want.

```d
import std;

void f(Variant x) {
     writeln(x);
}

void main() {
     f( Variant(42)    );
     f( Variant(2.5)   );
     f( Variant("Hi!") );
}
```


More information about the Digitalmars-d-learn mailing list