What is the reasoning behind the lack of conversions when passing parameters
Carl Sturtivant
sturtivant at gmail.com
Fri Feb 2 21:16:33 UTC 2024
```
import std.variant, std.math, std.stdio;
void f(Variant z) {
writeln(z);
}
void main() {
auto x = sqrt(2.0);
Variant v = x;
f(v);
//f(x);
}
```
The commented out call `f(x)` is illegal in D.
`f(VariantN!32LU v) is not callable using argument types (double)`
Yet in principle it is an attempt to create and initialize a
variable `z` local to `f` of type Variant.
Exactly like the legal `Variant v = x` declaration.
Why exactly is vanilla parameter passing not given the same
semantics as initialization?
More information about the Digitalmars-d
mailing list