Disappointing inflexibility of argument passing in D
Andrea Fontana
nospam at example.com
Tue Feb 11 08:50:02 PST 2014
On Tuesday, 11 February 2014 at 15:10:57 UTC, Carl Sturtivant
wrote:
>
> D has opAssign, making defining implicit conversions from any
> type to a new type possible on assignment, so where is the
> analogue (say opPass) for passing an argument to a function?
>
> void f( Data d, Data2 d2) { ..... }
>
> void main() {
> //conversions from string part of the definitions of
> Data, Data2
> f( "hello", "bonjour"); //no way to do this ---
> disappointing
> }
>
> See
> http://forum.dlang.org/thread/agstjpezerwlgdhphclk@forum.dlang.org
In the meanwhile maybe you can try a workaround with templates?
Something like:
void f(D1, D2)(D1 d, D2 d2) if (is(D1:Data) && is(D2 : Data2))
{
// Temp vars and assignment
...
...
f(tmpD1, tmpD2);
}
More information about the Digitalmars-d
mailing list