Clang 3.6 fold expression left / right

I am trying to use the fold expression with clang 3.6 '--std = C ++ 1z', but something I do not quite understand. Function I am testing:

auto minus = [](auto... args) { return (args - ...); }; ... std::cout << minus(10, 3, 2) << std::endl; 

according to n4191 , I expect it to expand as a left fold in

 (10 - 3) - 2 

which gives the result 5, but the result is 9, which, apparently, is a decomposition to the right, i.e.

 10 - (3 - 2) 

Am I missing something or didn’t understand n4191? Thanks

+7
c ++ clang clang ++ c ++ 17
source share
1 answer

n4191 was changed by n4295 . In accordance with this, the expression of the form (e op ...) is a unary right fold and expands as: E1 op (... op (EN-1 op EN)) , i.e. Like a decomposition to the right.

This seems to be the opposite of n4191 indicated in terms of the direction of the fold. Clang 3.6 implements n4295 proposal, as shown here .

... - args will be a unary left fold and will expand in the direction you need.

+6
source share

All Articles