It's not the order of parameter pack expansion which is different, it's the order of function argument evaluation.
f_Swallow
(
[&]()
{
result.push_back(arg);
return true;
}
()...
) ;
For sake of brevity, lets just give that lambda the name funcN
where N
is the parameter number. Given four arguments, the parameter pack will be expanded by any conforming compiler into this:
f_Swallow(func1(), func2(), func3, func4()) ;
The order of evaluation of function arguments is unspecified in C++. The compiler could evaluate them in-order (like your version of Clang), in reverse order (like your version of MSVC), or in any order it likes. You cannot count on the evaluation order.
To get what you want, you could put the expressions into a context in which the order of evaluation is specified. For example:
template <typename... T>
std::vector<int> f(T ...arg)
{
std::vector<int> result;
(void)std::initializer_list<int> { (result.push_back(arg), 0)... };
return result;
}
In C++17, you'll be able to do the following with fold expressions:
template <typename... T>
std::vector<int> f(T ...arg)
{
std::vector<int> result;
(result.push_back(arg), ...);
return result;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…