I've noticed a strange fact about shared_ptr
int* p = nullptr;
std::shared_ptr<int> s(p); // create a count (1).
std::shared_ptr<int> s2(s); // count go to 2.
assert(s.use_count() == 2);
I wonder what is the semantic beyond this. Why are s and s2 sharing a nullptr ? Does it makes any sense ?
Or maybe this uncommon situation doesn't deserve a if statement (costly ?) ?
Thanks for any enlightenment.
The semantics are:
nullptr_t
, it's empty; that is, it doesn't own any pointer.So your example isn't empty; it owns a null pointer.