[Phobos request] Op template

Meta via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 6 11:26:10 PDT 2016


On Wednesday, 6 July 2016 at 17:17:41 UTC, Temtaime wrote:
> Hi !
> I've found that next template will be convenient for use in 
> chains and cetera.
>
> Op!`+` == (a, b) => a + b
>
> For example: auto sum = arr.fold!(Op!`+`).
>
> Suggests ?

There's a couple templates that can be defined to cover the range 
of operators.

alias binop(string s) = (a, b) => mixin("a" ~ s ~ "b");
alias preop(string s) = a => mixin(s ~ "a");
alias postop(string s) = a => mixin("a" ~ s);


More information about the Digitalmars-d mailing list