I have a bunch of unique_ptrs for database connections. They get checked out by different parts of the code to run database queries, then returned (std::move) back to the container for next use.
I want to keep track of all instances of these unique_ptrs (db connections) by a weak_ptr to close the connections on a termination signal.
When unique pointers are checked out, I don't have a good way to call on all of them to close their connections immediately, since I don't have a link to them. Can I keep track of them by a container of weak_ptrs and access them via that container?
Is is possible to move a weak_ptr reference to a unique_ptr?
I am new to C++. I see other questions on SO, but they are different than what I want to do.
How can I do something like this:
unique_ptr<sql::Connection> conn_to_kill = std::move(weak_ptr_to_connection);