Overloading relational operators separately; thoughts?
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 30 12:18:26 PDT 2016
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));
}
More information about the Digitalmars-d
mailing list