Overloading relational operators separately; thoughts?
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 30 16:17:16 PDT 2016
On 30.09.2016 22:14, Andrei Alexandrescu wrote:
> On 09/30/2016 03:18 PM, Timon Gehr wrote:
>> On 30.09.2016 21:02, Timon Gehr wrote:
>>> On 30.09.2016 03:15, Chris Wright wrote:
>>>> ...
>>>
>>>> Wouldn't that be fun?
>>>>
>>>
>>> Certainly.
>>
>> On a related note:
>>
>> alias Seq(T...)=T;
>>
>> struct S{
>> int x;
>> S opBinary(string op:"+",T...)(T args){
>> S r=this;
>> foreach(a;args) r.x+=a;
>> return r;
>> }
>> }
>>
>> void main(){
>> import std.stdio;
>> assert(S(1) + Seq!(2,3,4) == S(10));
>> }
>
> That looks awfully cool! -- Andrei
>
[my code here]
More information about the Digitalmars-d
mailing list