What is the reasoning behind the lack of conversions when passing parameters
bachmeier
no at spam.net
Sat Feb 3 00:23:59 UTC 2024
On Friday, 2 February 2024 at 23:49:21 UTC, Carl Sturtivant wrote:
> Working around this design decision in some more-than-trivial
> situations *is* onerous. Not all coding is in the context of
> big software projects. Versatility matters.
>
> Someone might reasonably expect parameter passing and
> initialization to have the same semantics: after all, parameter
> passing /is/ initialization of parameters to arguments.
>
> D lacking this possibility in some form seems to be a design
> mistake.
I've long hated this inconvenience. It could be solved without a
language change by putting something like this in Phobos (I've
never actually written the code):
```
void foo(Variant x) {}
mixin(rewrite!(foo, Variant));
```
which would result in
```
void foo(T)(T x) {
foo(Variant(x));
}
```
More information about the Digitalmars-d
mailing list