I'm in need of a way to take a ´std::unique_ptr´ returned from a function and use that in an initialization list to initialize a std::vector
of them. I am willing to settle for any solution that involves initializing the std::vector
with a comma separated list (ie. variadic function returning the vector) but this process needs to use move semantics to take the returned ´std::unique_ptr´ data. The issue I am having can be seen in the code below:
#include <vector>
#include <memory>
std::unique_ptr<int> create(int value) {
return std::make_unique<int>(value);
}
int main() {
std::vector<std::unique_ptr<int>> myVec = { create(1), create(2), create(3) }; //this results in an error
return 0;
}
Error Info: C2280 'std::unique_ptr>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)': attempting to reference a deleted function c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0 737
I am using microsoft visual studios 2015 to compile the program.
Edit: as I said before I need some solution that involves simply a comma separated list of unique pointers, I can't seem to figure out how to variadic arguments that tell me the # of arguments like std::initializer_list can do. Is there some template or macro hack I can use to achieve this?