Skip to content

std::make_tuple()中折叠表达式在不同编译器的展开结果不同 #47

Answered by Mq-b
Odits asked this question in Q&A
Discussion options

You must be logged in to vote

std::make_tuple( process(Args{}) ... ) 不是折叠表达式。

求值任何表达式的任何部分,包括求值函数参数的顺序都未指明(一些例外在下文中列出)。编译器能以任何顺序求值任何操作数和其他子表达式,并且可以在再次求值同一表达式时选择另一顺序。

#include <cstdio>
 
int a() { return [std::puts](http://zh.cppreference.com/w/cpp/io/c/puts)("a"); }
int b() { return [std::puts](http://zh.cppreference.com/w/cpp/io/c/puts)("b"); }
int c() { return [std::puts](http://zh.cppreference.com/w/cpp/io/c/puts)("c"); }
 
void z(int, int, int) {}
 
int main()
{
    z(a(), b(), c());       // 允许全部 6 种输出排列
    return a() + b() + c(); // 允许全部 6 种输出排列
}

https://zh.cppreference.com/w/cpp/language/eval_order

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Odits
Comment options

Answer selected by Mq-b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
external-Issue 非仓库本身问题
2 participants