Question
Hi there. I have a bit weird question. Suppose you have a non-copiable stack object, which you have gotten from an external library. How is it possible to move the content into a heap object allocated by std::make_shared without actually instantiating the class?
class my_class {
private:
my_class(my_class const&) = delete;
public:
my_class(some_arg_t some_args);
my_class(my_class&& move);
}
// later on
std::unordered_set<std::shared_ptr<my_class>> shared_pointers_container;
int foo() {
my_class obj = getMyClassObject();
shared_pointers_container.insert(// moving obj into heap memory and get the shared pointer to it)
}
One "solution" could be to create an instance of the object and then replace it, like shown below
std::shared_ptr<my_class> ptr = std::make_shared<my_class>(arguments_needed);
*ptr.get() = std::move(obj);
shared_pointers_container.insert(ptr);
but it's not a good solution (in case the constructor does some changes).
Maybe a way to tell std::make_shared to move the content of newly created object from the specified object?