Racchiudere parametri di un modello variadic nelle liste di inizializzazione dovrebbero assicurare che stanno valutati in ordine, ma non sta accadendo qui:C++ 11 liste di inizializzazione sui parametri del modello variadic: Perché non è questo lavoro
#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;
}
Come mai?
Errore del compilatore? Dal tuo link fornito, passando da gcc a clang o Intel produrrai i risultati che ti aspetti. –
Hai ragione Drew, Clang lo sta facendo bene – Paul
(o comportamento non definito ...) –