This question already has an answer here:
- Calling initializer_list constructor via make_unique/make_shared 2 answers
In modern C++ we can initialize a vector like this:
std::vector<int> v = { 1, 2, 3, 4, 5 };
But if I try creating a smart pointer to a vector, this won't compile:
auto v = std::make_shared<std::vector<int>>({ 1, 2, 3, 4, 5 });
Is there any better alternative than resorting to push_back
s after creation?