I have a suggestion for two new member functions for shared_ptr<X> .
Both give useful information that is currently available, but in non-obvious
or potentially inefficient ways.

1)  bool empty() const
       returns true if the shared_ptr does not own an object, and false if
it does own an object.  It is currently possible to determine this
information for a shared_ptr x by typing
   if (x.shared_count() == 0)

but this may be inefficient.


2)  template<class Y>
     bool shares_ownership_with(shared_ptr<Y> rhs) const

    returns true if and only if *this and rhs own the same object.

    It is currently possible to determine if two shared_ptr's x and y share
ownership by typing
    if ((x.use_count() > 0) && !(x < y) && !(y < x))

but this is long-winded and does not make it clear to a reader what the
coder is trying to do.

Joe Gottman






_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to