Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-03-18 13:11:24

alexoss_at_[hidden] wrote on 3/18/01 10:46 AM
>7. Are there situations in which use_count() and unique() are
>helpful to have? I've never needed to know this information about my
>old reference-counted pointer class.

I've sometimes used a shared_ptr's unique to help implement a class that
has value semantics, but has refcounted internals for performance reasons:

class ValueSemantics
        void modify_me();
        void inspect_me() const;
        shared_ptr<Internals> data_;

        if (!data_.unique())
                // get private copy of data
                data_ = shared_ptr<Internals>(new Internals(*data_));
        // Now modify knowing data_ is unique
        // ...

ValueSemantics::inspect_me() const
        // Just use *data_, no need for unique
        // ...


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