Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::none for boost::shared_ptr
From: Nevin Liber (nevin_at_[hidden])
Date: 2014-01-30 11:18:03


On 30 January 2014 01:12, Ben Pope <benpope81_at_[hidden]> wrote:

>
> Then, removing the #if !defined( BOOST_NO_CXX11_NULLPTR ) guard from the
> constructor of shared_ptr that accepts a boost::detail::sp_nullptr_t does
> indeed seem to work.
>
> namespace boost {
> namespace detail {
> struct sp_nullptr_t {};
> }
> const detail::sp_nullptr_t nullptr = detail::sp_nullptr_t();
> }
>
> #include <boost/smart_ptr/shared_ptr.hpp>
>
> int f(boost::shared_ptr<int> i) { return i ? *i : 0; }
>
> int main()
> {
> f(boost::nullptr);
> }
>
> ...there's probably some reason I'm not thinking of.

You can read the paper behind std::nullptr at <
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf>. The
short answer is (a) boost::sp_nullptr_t isn't convertible to any pointer or
pointer-to-member type, and (b) you really don't want to use
boost::nullptr, given that nullptr is a keyword in C++11.

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net