ResourceAndRole: explicitly handle weak_ptr to shared_ptr casts
The C++ standard's std::shared_ptr
only provides an explicit
constructor from std::weak_ptr
that throws if the std::weak_ptr
doesn't have any strong references left. GCC 7 refuses to compile the
previous code since there is no eligible constructor between the two.
Instead, explicitly loop and only add resources which successfully lock.