[OT] ISO C++ 17 changes

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 5 01:47:08 PDT 2017


On Tuesday, 4 April 2017 at 13:30:47 UTC, Meta wrote:
> On Tuesday, 4 April 2017 at 08:38:32 UTC, Walter Bright wrote:
>> http://dlang.org/phobos/std_algorithm_iteration.html#.fold
>
> Not quite the same as this is a fold over a TypeTuple/AliasSeq. 
> You could of course do:
>
> only(args).fold!"a + b"()
>
> But the semantics are different.

To avoid the runtime loop above, we could add an overload 
fold(alias fun, A...)(A args). (There are already min, max that 
take variadic arguments in std.algorithm). I think this would be 
more powerful than the C++ feature as it would support any 
function.

To make it a little nicer, we could have binaryFun accept 
operators as strings, e.g. fold!"+"(args). Doing that would allow 
e.g. sort!">"(r).


More information about the Digitalmars-d mailing list