[OT] ISO C++ 17 changes

Meta via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 4 06:45:47 PDT 2017


On Tuesday, 4 April 2017 at 13:38:57 UTC, ag0aep6g wrote:
> On 04/04/2017 03:29 PM, Meta wrote:
>> On Tuesday, 4 April 2017 at 05:04:04 UTC, Dukc wrote:
> [...]
>>>     fold!"+"(1, 2, 3).writeln; //6
> [...]
>> However, it's still more verbose. My goal was to emulate 
>> almost exactly
>> what C++ was doing by using a template so you could just write
>> "fold!('+', args)"
>
> I'm probably missing something, but `fold!"+"(args)` isn't more 
> verbose than `fold!('+', args)`.

I mean what goes on inside fold. If you look at the C++ example 
it's very concise and IMO beautiful:

<typename ...Args> auto f(Args ...args) { return (0 + ... + 
args); }

So I wanted a solution that was about the same in terms of 
brevity. My first attempt was:

enum fold(string op, Args...) = mixin("Args[0] " ~ op ~ " 
fold!(op, Args[1..$])";

But of course this doesn't work.


More information about the Digitalmars-d mailing list