Order of Evaluation for Fold Expressions

旧巷老猫 提交于 2019-12-06 01:35:37
Nicol Bolas

A right-fold over an operator expands like this: ... (arg0 op (arg1 op arg2)). So while the parens help, they don't guarantee anything about the order of the individual elements.

Therefore, it's all left up to op. And the comma operator (which is distinct from commas separating function arguments), even pre-C++17, is a hard sequence point. It ensures left-to-right evaluation with no cross-talk.

If you had instead used +, there would be no sequencing guarantees. So it depends on the operator you use. C++17 added a few more operators that have strict sequencing guarantees (<<, for example).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!