Consider the following code:
struct Bar
{
std::shared_ptr<int> MemberFunction()
{
return std::move(m_memberVariable);
}
std::shared_ptr<int> m_memberVariable;
};
Is it guaranteed that the std::move
from a shared_ptr<T>
will actually remove the reference in the member variable? Or should I copy, clear and return copy to guarantee this*
Clearly in the case of unique_ptr<T>
it does the right thing (it cannot possibly not do) but does the standard guarantee that a std::move
d from shared_ptr
releases its reference? [when it is a member variable, static or global, locals don't matter as they go out of scope]
*possibly "swap and return" is better than "copy, clear and return".