The constructor std::vector<double> can use the int curly list for its constructor std::vector<double>(std::initializer_list<double>) .
emplace_back() cannot emplace_back() element from the curly brackets expression because it is a template that uses perfect forwarding. The standard prevents the compiler from inferring the type {0,0} , so std::vector<double>::emplace_back<std::initializer_list<double>>(std::initializer_list<double>) does not compile for emplace_back({}) .
Another answer indicates that emplace_back can be compiled for an argument of type std::initializer_list<T> if it should not infer the type directly from the expression {} . As an alternative to casting an argument to emplace_back , you can first emplace_back argument. As stated in clause 30 of Meyers (Effective Modern C ++), auto allowed to display the type of curly bracket expression, and with perfect transfer, it is the type of object whose type was deduced by auto .
std::vector<std::vector<double> > vec; auto int_list = {0, 0};
emplace_back adds an element to vec by calling std::vector<double>(std::forward<std::initializer_list<int>>(int_list)) , which calls std::vector<double>(std::initializer_list<double>) constructor and int_list elements int_list converted.
MEI
source share