Boost logo

Boost :

From: Jeff King (peff-boost_at_[hidden])
Date: 2001-11-25 12:09:41

On Sun, 25 Nov 2001, John Maddock wrote:

> Yes, the problem is when two headers included by the same translation unit
> use namespace scope static assertions - if the assertions are on the same
> line in their header files, and in the same namespace, then some compilers
> complain, others generate warnings, but otherwise accept the code. It's
> easier to suggest a unique namespace, than to try to explain why in some
> really obsure case the code stops working...

Err...right. So you have the obscure (but possible) problem of
accidentally declaring the exact same "unique" namespace in two files
(which might be more common across a large project). Isn't solving that
the entire purpose of the anonymous namespace?

You could even declare a STATIC_ASSERT that put itself in the anonymous
namespace automagically, but that means a different STATIC_ASSERT macro
for namespaces (since you can't open a namespace in function or class
scope, IIRC).

My point is to suggest:

Why not use the anonymous namespace, which actually provides a unique
name for you? It seems simpler to explain, and lets the compiler do the
work of coming up with a unique name (which is guaranteed to work!).
Is there some reason I don't know of not to recommend the anonymous
namespace for this?


Boost list run by bdawes at, gregod at, cpdaniel at, john at