Operator overloading

Don nospam at nospam.com
Wed Dec 24 12:38:16 PST 2008


aarti_pl wrote:
> Andrei Alexandrescu pisze:
>  > We're trying to make that work. D is due for an operator overhaul.
>  >
>  > Andrei
> 
> Is there any chance that we get possibility to overload "raw operators", 
> like in C++? I think that they may coexist with currently defined 
> operator overloads with simple semantic rules, which will not allow them 
> to work together at the same time.
> 
> I know that they may obfuscate code, but they are extremely useful when 
> defining in D domain specific languages. For example I try to make SQL 
> expressions work as D expressions:

> 
> string query = "SELECT * FROM a WHERE id=5;";
> -->
> Query query = Select(a).Where(Equals(id, 5));
> 
> * "id" is D object in second expression
> 
> This translation is quite awful and unreadable. It would be so much 
> better to get:
> 
> Query query = Select(a).Where(id == 5);

I think that's still awful. I prefer:
Query query = mixin(SQL("SELECT * FROM a WHERE id=5"));


> 
> With implicit casts there will be perfect environment, to define DSL-s 
> *in* D and *not* using unsafe strings.
> 
> BR
> Marcin Kuszczak
> (aarti_pl)



More information about the Digitalmars-d mailing list