initializer_list and template type deduction

Your first line printme({‘a’, ‘b’, ‘c’}) is illegal because the template argument T could not be inferred. If you explicitly specify the template argument it will work, e.g. printme<vector<char>>({‘a’, ‘b’, ‘c’}) or printme<initializer_list<char>>({‘a’, ‘b’, ‘c’}). The other ones you listed are legal because the argument has a well-defined type, so the template argument T can … Read more

Can I list-initialize a vector of move-only type?

Edit: Since @Johannes doesn’t seem to want to post the best solution as an answer, I’ll just do it. #include <iterator> #include <vector> #include <memory> int main(){ using move_only = std::unique_ptr<int>; move_only init[] = { move_only(), move_only(), move_only() }; std::vector<move_only> v{std::make_move_iterator(std::begin(init)), std::make_move_iterator(std::end(init))}; } The iterators returned by std::make_move_iterator will move the pointed-to element when being … Read more