铸造 – C 17:“折叠”概念中“具有优先权的 *** 作符”是什么意思?

铸造 – C 17:“折叠”概念中“具有优先权的 *** 作符”是什么意思?,第1张

概述http://en.cppreference.com/w/cpp/language/fold的网站给出了如何使用折叠概念的例子,它说: NoteIf the expression used as init or as pack has an operator with precedence below cast at the top level, it can be parenthese http://en.cppreference.com/w/cpp/language/fold的网站给出了如何使用折叠概念的例子,它说:
NoteIf the Expression used as init or as pack has an operator with precedence    below cast at the top level,it can be parenthesed:template<typename ...Args>int sum(Args&&... args) {//    return (args + ... + 1 * 2); // Error: operator with precedence below cast    return (args + ... + (1 * 2)); // OK}

作为一个非英语母语的人,我不退出这句话:

has an operator with precedence below cast at the top level

它实际意味着什么,它的例子,它表明了什么?
你能帮忙解释一下吗?

非常感谢.

解决方法 转换运算符((Typename)expr)在 C++’s operator precedence rules中具有非常高的优先级.很少有运算符具有更高的优先级.具有强制级别或更高优先级的 *** 作符是非常特殊的 *** 作,通常应用于单个表达式.

在表达式args … 1 * 2中,…适用于左侧和右侧的所有内容.但“右翼”究竟意味着什么呢?它只意味着1部分,还是1 * 2?

对于具有高优先级的运算符,很明显意图是什么.例如,args … func(),很明显()函数调用运算符适用于func而不适用于args … func.如果你这样做((args … func)()),你就不太可能想要后者强制你明确地使用括号.

然而,对于图表中优先级低于3的情况,人们理解的事情会变得多云.因此,C不是使用正常的优先级规则,而是强制用户明确它.你可以有args …(1 * 2)或(args … 1)* 2.但是你必须清楚你想要哪一个.

总结

以上是内存溢出为你收集整理的铸造 – C 17:“折叠”概念中“具有优先权的 *** 作符”是什么意思?全部内容,希望文章能够帮你解决铸造 – C 17:“折叠”概念中“具有优先权的 *** 作符”是什么意思?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1258055.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存