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.

Reply via email to