Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::none for boost::shared_ptr
From: John M. Dlugosz (ngnr63q02_at_[hidden])
Date: 2014-02-03 11:19:16


On 1/30/2014 1:12 AM, Ben Pope wrote:
> Yes, of course. Internally boost::shared_ptr uses boost::detail::sp_nullptr_t, which in
> C++11 is a typedef of std::nullptr_t, there appears to be no alternative for C++98, which
> is a shame.
>
> I don't see why that type couldn't be defined to an empty struct in C++98 mode.

That works for my own classes:
If nullptr_t is not available on the platform, I define a class by that name in my own
detail namespace. When defining a class that has a member function taking a parameter of
type nullptr_t, no conditional compilation is needed around it, and it finds the
definition in the current namespace.
If the user of the class defines his own value of type libraryName::nullptr_t, that
function can be called.

I have not experimented with providing a templated conversion operator to allow
libraryName::nullptr_t to be converted to any T*. That should satisfy at least some uses
of nullptr literal, although it counts as a user-defined conversion.

—John


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