括在初始化列表一個可變參數模板的參數應該保證他們爲了評估,但沒有發生在這裏: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
(或未定義的行爲...) –