
"Arkadiy Vertleyb" <vertleyb@hotmail.com> writes:
"David Abrahams" <dave@boost-consulting.com> 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