Edit: It is not duplicated of the linked question (which is mine also). Here all the return types are
std::vector. I do not want to return aninitializer-list. I want to fill the returnedstd::vectorbyinitializer-listdirectly
Let us take those four cases:
1)
//Acceptable
std::vector<int> foo(){
return std::vector<int>{1};
}
2)
//Acceptable
std::vector<int> foo(){
return {1};
}
3)
//Acceptable
std::function<std::vector<int>()> foo=[](){
return std::vector<int>{1};
};
4)
//NOT Acceptable
std::function<std::vector<int>()> foo=[](){
return {1};
};
Why 4 is not acceptable since 2 is acceptable? what is the different between them? Moreover, the most strange thing that this is acceptable:
//Acceptable
auto bar=[]()->std::vector<int>{
return {1};
};
What is wrong with std::function and initializer-list?
Aucun commentaire:
Enregistrer un commentaire