Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2003-05-27 15:12:14

   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

Boost list run by bdawes at, gregod at, cpdaniel at, john at