ang 3.6倍表达左/右 [英] clang 3.6 fold expression left/right

查看:188
本文介绍了ang 3.6倍表达左/右的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图折叠表达式与clang 3.6'--std = c + + 1z',但我不太明白的东西。我测试的功能是:

I'm trying the fold expression with clang 3.6 '--std=c++1z', but something I don't quite get. The function that I'm testing is:

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

根据 n4191 ,我希望它展开为左折叠到

according to n4191, I'm expecting it expands as a left fold to

(10 - 3) - 2

结果是9,这似乎是正确的倍数扩展,即

which gives result 5, however, the result is 9, which seems to be a right fold expansion, i.e.

10 - (3 - 2)

我缺少任何东西或错误理解n4191?
感谢

Am I missing anything or mis-understand n4191? Thanks

推荐答案

n4191由n4295 。根据这一点,形式(e op ...)的表达式是一元右侧折叠,并且扩展为: E1 op(... op(EN-1 op EN)),即作为右侧展开。

n4191 was revised by n4295. According to that, an expression of the form (e op ...) is a unary right fold, and that is expanded as: E1 op (... op (EN-1 op EN)), i.e. as a right fold expansion.

似乎与n4191在折叠方向上所说的相反。 Clang 3.6实施n4295提案,如此处所示。

This does seem to be the reverse of what n4191 stated in terms of the fold direction. Clang 3.6 implements the n4295 proposal, as shown here.

... - args 将是一元左折,并按您想要的方向展开。

... - args would be a unary left fold and expand in the direction you want.

这篇关于ang 3.6倍表达左/右的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆