Overloading relational operators separately; thoughts?
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 30 13:14:52 PDT 2016
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
More information about the Digitalmars-d
mailing list