Disappointing inflexibility of argument passing in D
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Feb 11 08:38:42 PST 2014
On 2/11/14, 7:10 AM, 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
Hmmm... very interesting. I was thinking of the same these days because
we have qualifier(T[]) automatically change to qualifier(T)[] upon
passing to a function. However, there is no way for the user to specify
such type change for a user-defined type.
Adding some sort of opPass would help solve the current problem we have
with passing const ranges into functions. (Currently they won't work
unless they're built-in slices).
Andrei
More information about the Digitalmars-d
mailing list