Overloading relational operators separately; thoughts?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 28 13:40:49 PDT 2016


On 28.09.2016 22:16, Walter Bright wrote:
> On 9/28/2016 6:58 AM, Timon Gehr wrote:
>>> An excellent example of that is the std.regex package.
>> It's actually a bad example, because it is irrelevant: it is obviously
>> a bad
>> idea to implement regex using operator overloading, because the regex
>> operators
>> have no D equivalent.
>
> Yet this "obviously bad" idea regularly resurfaces as a cool use of
> expression templates and respected people in the industry like it and
> advocate it.
> ...

This is not surprising. C++ has no good options.

>
>> Assume I have two symbolic expressions a and b:
>>
>> Expression a=variable("a"), b=variable("b");
>>
>> Why should I be allowed to do
>>
>> auto c = a + b; // symbolic value a + b
>>
>> but not
>>
>> auto d = a <= b; // symbolic value a <= b
>
> Because there is no way to stop the former but still have operator
> overloading.
> ...

What's wrong with that usage? (This is NOT expression templates.)

>
>> The string parsing approach is not useful here: how do I use existing
>> expressions that are accessible in the scope to build new expressions?
>
> You seem to be asking for expression templates.

No. It's symbolic computation at run time. Think Wolfram Mathematica.


More information about the Digitalmars-d mailing list