Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-29 12:30:58


"Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote
>
>> Yeah, but be really careful, because there are only a few good ways
>> to use an unnamed namespace in a header. In fact, the only legitimate
>> way to fix the Boost.Bind placeholder issue for header-only libs,
>> without ODR or order-of-initialization issues, is:
>>
>> // placeholders.hpp
>> template <class SomePOD>
>> static pod_singleton
>> {
>> const SomePOD instance;
>> };
>>
>> template <class SomePOD>
>> SomePOD const pod_singleton::instance = { /*optional contents*/ };
>>
>> namespace
>> {
>> some_pod const& _1 = pod_singleton<some_pod>::instance;
>> }
>>
>> That's an unnamed namespace in a header.
>
> Why doesn't it have ODR issues? Isn't it still possible to cause ODR
> violation by using _1 inside a class/template definition in a
> header?

Instances of _1 all refer to the same object
(pod_singleton<some_pod>::instance), thus no ODR violation. See the
standard ODR text if you need to be convinced.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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