2014-11-19 16:40 GMT+01:00 Sylvester-Bradley, Gareth < Gareth.Sylvester-Bradley@eu.sony.com>:
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.