Boost logo

Boost :

Subject: Re: [boost] Why no non-null smart pointers?
From: Jeff Hill (johill_at_[hidden])
Date: 2014-04-28 12:16:18


Perhaps there is even a backwards compatible solution. Could we employ an
optional null object pattern in methods and or constructors of shared_ptr
that might establish a raw nill state? Perhaps something like this obviously
oversimplified example could be use.

template < typename T>
void shared_ptr < T > :: reset ( T * p = 0 )
{
    if ( p ) {
          /* what happens in shared_ptr now */
    }
    else {
        /* new behavior in shared_ptr, when it detects a nill raw pointer */
        static NullObjectTypes < T > nullObject;
        *this = shared_ptr < T > ( &nullObject, NullObjectTypes < T > ::
deleter () );
    }
}

Jeff

--
View this message in context: http://boost.2283326.n4.nabble.com/Why-no-non-null-smart-pointers-tp2642959p4661799.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk