Boost logo

Boost :

Subject: Re: [boost] [optional] How to define boost::none?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2014-11-19 10:56:09


2014-11-19 16:40 GMT+01:00 Sylvester-Bradley, Gareth <
Gareth.Sylvester-Bradley_at_[hidden]>:

> 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;
>
> }
> // ?
>
> Thanks,
> Gareth
>

With anonymous namespace the variable becomes TU-local (translation
unit-local), which guarantees no ODR violation. But instead repeats the
same declaration in every TU.


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