On 10/7/2013 10:48 PM, Quoth Thorsten Ottosen:
If the idea is to be 100% shared_ptr interface compatible, it may be easier just to extend boost::shared_ptr a little:
typedef boost::shared_ptr<boost::non_nullable<T>> SharedT;
I don't like that. If you're suggesting using a wrapper type without changing shared_ptr, that won't work because the shared_ptr itself could still be empty, so you haven't gained anything. If you're suggesting specialising shared_ptr for that subtype, I don't see any benefit in doing this over defining a new pointer type, since you have to redefine everything in a specialisation anyway. And there's undoubtedly some existing templated code that operates on boost::shared_ptr<T> that would be confused by this, or at the very least not operate efficiently by including tests for null.
typedef boost::shared_ptr<boost::non_nullable<T>> WeakT;
I assume that was a typo. (Weak pointers are not especially useful without being able to represent null anyway.)