Boost logo

Boost :

Subject: Re: [boost] [config] Macro for null pointer
From: Eric Niebler (eric_at_[hidden])
Date: 2012-12-04 17:41:43


On 12/4/2012 2:21 PM, Jeffrey Lee Hellrung, Jr. wrote:
> On Tue, Dec 4, 2012 at 2:14 PM, Peter Dimov <lists_at_[hidden]> wrote:
>
>> Eric Niebler wrote:
>>
>>> ... until some other library ALSO defines a global nullptr symbol,
>>> making that library and boost mutually incompatible.
>>>
>>
>> How is the end user supposed to actually use nullptr if it's not global?
>> It's a keyword in C++11; boost::nullptr is not legal.
>
> namespace X
> {
>
> BOOST_USING_NULLPTR;
>
> void foo() { int * p = nullptr; }
>
> } // namespace X
>
> is the basic usage I had proposed. BOOST_USING_NULLPTR expands to some
> empty statement in C++11 and "using ::boost::nullptr" in C++03.

Right. In my understanding, it could work like this:

    // Some stupid lib does this:
    constexpr struct mynullptr_t {} mynullptr {};

    // Boost does this:
    namespace boost
    {
        constexpr struct mynullptr_t {} mynullptr {};
    }

    #define BOOST_USING_NULLPTR \
        using boost::mynullptr_t; \
        using boost::mynullptr

    // Third-party code does this:
    namespace my
    {
        BOOST_USING_NULLPTR;
        void foo()
        {
            mynullptr_t x;
            x = mynullptr;
        }
    }

No ambiguity.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk