Disappointing inflexibility of argument passing with "alias this"

Kagamin via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 23 04:43:42 PST 2016


On Tuesday, 23 February 2016 at 01:02:21 UTC, Jonathan M Davis 
wrote:
> Yeah. Sometimes having implicit conversions is great. Other 
> times, it creates tons of problems. C++ allows a lot of 
> implicit stuff, and it becomes really easy to have unexpected 
> conversions going on, and it can be difficult to figure out 
> exactly what code is being called. For the most part, D doesn't 
> have any of those problems, but it arguably loses some 
> usability as a result.

Don't we already have implicit conversions with alias this, so 
what's the deal?

struct A { int i; alias i this; }
void f(int i){}
void f(string s){}
void g(A a){ f(a); } //what's called?


More information about the Digitalmars-d mailing list