
Brendan Miller skrev:
On Sat, Nov 15, 2008 at 2:49 AM, Thorsten Ottosen <thorsten.ottosen@dezide.com> wrote:
Brendan Miller skrev:
I've been interested in non nullable smart pointers for a while. I noticed a thread I wanted to check if anyone was still interested in doing it: http://lists.boost.org/Archives/boost/2008/04/135616.php
This seems like a worthwhile activity. Null is a legacy element from C that essentially breaks type safety. FWIW, Boost.PtrContainer does not allow you to put nulls in containers; if you want nulls you have to ask for it:
boost::ptr_vector< boost::nullable<T> > vec;
I'm always shocked how many good ideas have already been implemented in boost.
I guess it would be trivial to add something like
typedef boost::shared_ptr< boost::non_null<T> > ptr_type;
which would not be default constructible, and which would throw if you inserted a null (rather than providing a check in operator->).
You're suggesting that there would be a specialization of shared_ptr for shared_ptr<boost::non_null<T>>? That's a good idea, but I have no idea on whether the maintainers of shared_ptr are willing to accept that much more complexity.
Well, full specializations is not necessary. Some simple TMP should be enough. -Thorsten