Boost logo

Boost :

Subject: Re: [boost] [optional] How to define boost::none?
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-11-19 11:06:01


On Wed, Nov 19, 2014 at 6:40 PM, Sylvester-Bradley, Gareth
<Gareth.Sylvester-Bradley_at_[hidden]> wrote:
> Hi Andrey,
>
> On Wed, Nov 19, 2014 at 3:27 PM, Andrey Semashev wrote:
>> Since none has internal linkage, it is translation unit-specific.
>> Technically, this can cause ODR violations in some cases. To avoid
>> that you can declare it like this:
>>
>> struct none_t {};
>>
>> template< typename T >
>> struct singleton
>> {
>> static const T instance;
>> };
>> template< typename T >
>> const T singleton< T >::instance = T();
>>
>
> // Do we need...
> namespace
> {
>
>> const none_t& none = singleton< none_t >::instance;
>
> }
> // ?

It seems so. I thought references don't have linkage but it looks like
I was wrong. It doesn't add ODR violations though.


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