Under what situations would it be valid to compare shared_ptr instances instead of the underly lying type the shared_ptr manages?
As an example, would there ever be a situation where the size of personset being 2 would be valid after the following code has run?
shared_ptr<person> p0 = make_shared<person>(....);
shared_ptr<person> p1 = p0;
set<shared_ptr<person>> personset;
personset.insert(p0);
personset.insert(p1);
There is no viable reason to compare the instances. Infact shared_ptrs by default will perform equality/inequality comparators based via the underlying pointer to the control block (via .get method).
http://en.cppreference.com/w/cpp/memory/shared_ptr/operator_cmp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With