Boost logo

Boost :

Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2013-10-02 18:43:19

On Wed, Oct 2, 2013 at 3:19 PM, Mostafa <mostafa_working_away_at_[hidden]>wrote:

> Maybe I'm just being thick, why can't you just cast it/wrap it as a
> shared_ptr obj before passing it to such generic code?

You're not being thick and it's not really a huge deal. Yes, you can always
wrap it, though you once you do that and pass it off, you're losing some of
the benefit of it being non-null and also doing a conversion. Another
example of something similar -- why does std::array have a size function
(I.E. not just an associated size value)? The size is always known at
compile time (just like our non-null-ness is known at compile-time). The
reason is so that it models the container concept, of course, and is usable
in contexts that expect a container. It's also simply consistent with
existing practice. In our case with the non-null pointer template, we don't
have an explicit concept to model, but it doesn't hurt to be mindful of
consistency. Pointers and smart pointer types generally support checking
for null, and we lose nothing by respecting that convention. It also makes
drop-in replacement easier while keeping the proper behavior.

-Matt Calabrese

Boost list run by bdawes at, gregod at, cpdaniel at, john at