Off the top of my head, I only remember LLVM's standard library do this, but I remember seeing other libraries also do this. I'm not entirely sure what is the advantage here. I feel like namespace std { would be clearer than _LIBCPP_BEGIN_NAMESPACE_STD?
7 Replies
It's useful for compatibility, testing, etc. For example you may want to make use of inline namespaces but also support compilers that don't have that feature, yet, so you make it possible to disable it via the preprocessor.
LLVM itself also adds some other macros on top of the namespace declaration, making the macro shorter and avoiding repetition. See its definition in this file
Qt optionally uses a namespace to avoid linker errors in certain configurations. If Qt started today, they'd probably always use a namespace (and some inline namespaces on top) but it's a pretty old library with high regards for backwards compatibility, so they can't change now.
If for some reason you need to use two versions of the same library in a single binary, you can change the namespace of one copy
BTW, don't look to standard library implementations for code that can be used in reasonable user programs. Remember that the standard library may make non-portable assumptions about the compiler it's used with, and is allowed to use otherwise-reserved identifiers (such as the macro name mentioned in this question).