Boost logo

Boost Users :

Subject: Re: [Boost-users] non nullable smart pointers
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-11-17 04:00:38

Brendan Miller skrev:
> On Sat, Nov 15, 2008 at 2:49 AM, Thorsten Ottosen
> <thorsten.ottosen_at_[hidden]> 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:
>>> 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


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at