Operator overloading

Denis Koroskin 2korden at gmail.com
Tue Dec 23 12:25:01 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);
> 
> With implicit casts there will be perfect environment, to define DSL-s 
> *in* D and *not* using unsafe strings.
> 
> BR
> Marcin Kuszczak
> (aarti_pl)

Slightly off-topic.

How would you implement, say, LIKE condition? Similar to the following, perhaps:
Query query = Select(a).Where(id.Like("%substring%"));

You could implement "==" the same way:
Query query = Select(a).Where(id.EqualsTo(5));



More information about the Digitalmars-d mailing list