Listing 5: Replacing the reference count with a pointer to another Context.

class InValueContainer2 {
    public:
        FreeDefaultContext2(): _other(NULL) {}
        bool soleOwner() const {return _other == NULL;}
    public: // allow copy construction and assign
        FreeDefaultContext2(FreeDefaultContext2& rhs)
            : _other(&rhs) {
            assert(rhs._other == NULL); // line 1
            rhs._other = this;
        }
        void operator=(const FreeDefaultContext2& rhs) {
            assert(rhs._other == NULL); // line 1

            if (_other) _other->_other = NULL; 
            _other = &rhs;
            rhs._other = this;
        }
    private:
        InValueContainer2* _other;
};