括在初始化列表一个可变参数模板的参数应该保证他们为了评估,但没有发生在这里:C++ 11初始化列表:为什么不是这方面的工作
#include <iostream>
using namespace std;
template<class T> void some_function(T var)
{
cout << var << endl;
}
struct expand_aux {
template<typename... Args> expand_aux(Args&&...) { }
};
template<typename... Args> inline void expand(Args&&... args)
{
bool b[] = {(some_function(std::forward<Args>(args)),true)...}; // This output is 42, "true", false and is correct
cout << "other output" << endl;
expand_aux temp3 { (some_function(std::forward<Args>(args)),true)... }; // This output isn't correct, it is false, "true", 42
}
int main()
{
expand(42, "true", false);
return 0;
}
怎么回事?
编译器错误?从您提供的链接中,从gcc切换到叮当或英特尔将产生您期望的结果。 –
你是对的德鲁,铛是这样做的 – Paul
(或未定义的行为...) –