Inline namespaces are a C++11 feature designed to support library versioning.
Questions tagged [inline-namespaces]
18 questions
415
votes
6 answers
What are inline namespaces for?
C++11 allows inline namespaces, all members of which are also automatically in the enclosing namespace. I cannot think of any useful application of this -- can somebody please give a brief, succinct example of a situation where an inline namespace…

Walter
- 44,150
- 20
- 113
- 196
27
votes
2 answers
Wherefore inline unnamed namespaces?
A quick one for the gurus: C++11 allows unnamed namespaces to be declared inline. This seems redundant to me; things declared in an unnamed namespace are already used as if they were declared in the enclosing namespace.
So my question is this: what…

Tristan Brindle
- 16,281
- 4
- 39
- 82
26
votes
1 answer
What is the benefit of std::literals::.. being inline namespaces?
In the C++-Standard (eg. N4594) there are two definitions for operator""s:
One for std::chrono::seconds :
namespace std {
...
inline namespace literals {
inline namespace chrono_literals {
// 20.15.5.8, suffixes for duration literals
constexpr…

towi
- 21,587
- 28
- 106
- 187
25
votes
3 answers
How can I explicitly refer to an enclosing namespace when an inline namespace exists?
Please consider this code:
#include
namespace Foo{
void ool() // Version A
{
std::cout << "Foo::ool" << std::endl;
}
inline namespace Bar{
void ool() // Version B
{
std::cout <<…

YvesQuemener
- 601
- 5
- 16
18
votes
2 answers
Ambiguous reference to namespace within an inline namespace
Assume the following code:
namespace test
{
namespace detail
{
}
inline namespace v1
{
namespace detail
{
void foo()
{
}
}
}
}
int main()
{
…

Griwes
- 8,805
- 2
- 43
- 70
13
votes
1 answer
Why does range-v3 put its function objects into an inline namespace?
In range-v3, all of the functions are really global function objects in an inline namespace:
#if RANGES_CXX_INLINE_VARIABLES < RANGES_CXX_INLINE_VARIABLES_17
#define RANGES_INLINE_VARIABLE(type, name) \
inline…

Barry
- 286,269
- 29
- 621
- 977
8
votes
1 answer
Does boost use C++11 "inline namespaces" to avoid ABI incompatibilty errors at runtime?
C++11 has a feature called "inline namespaces", which allows authors to enforce ABI compatibility at link time without tampering with the API. For instance, these helpful answers from @HowardHinnant explain how libc++ uses inline namespaces:
Using…

Stuart Berg
- 17,026
- 12
- 67
- 99
7
votes
3 answers
How to get Coverity static analysis compatible with C++0x standard?
I am using a Wind River Compiler 4 (gcc (C) and g++ (C++)) and it compiles all my projects without any problems. Now I have to use Coverity Static Analysis to check my code. I have configured the specific compilers. For the C-Code (gcc) there are no…

Indimental
- 846
- 1
- 8
- 10
5
votes
1 answer
How can I access a C++ function if an inline namespace has the same function?
The following situation:
namespace abc{
inline namespace x{
int f() { return 5; }
}
inline namespace y{
int f() { return 6; }
}
int f() { return 7; }
void g(){
x::f(); // okay
y::f(); //…

Benjamin Buch
- 4,752
- 7
- 28
- 51
4
votes
2 answers
inline namespace technique for managing platform specific code in c++
I have seen usage of #ifdef macros ( example Eigen library ) to manage platform specific, but haven't seen any one use "inline namespace"s to manage platform specific code.
The github repo belows gives specific code and example…

Tej
- 61
- 3
3
votes
1 answer
Inline namespace emulation for MSVC (10.0/11.0)
Is there any way to emulate an inline namespace with MSVC?
LLVM's libc++ uses this to create a hidden versioned namespace like so:
#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE {
#define…

rubenvb
- 74,642
- 33
- 187
- 332
3
votes
2 answers
using "multiple"namespaces one-liner
is there a simplified way to include more namespaces instead of typing every time the same things. This is very annoying, especially in the .h files.
For instance:
Instead of writing:
int f() {
using namespace blabla1;
using namespace…

veltres
- 51
- 5
3
votes
1 answer
Using type from inline namespace in cpp file does not work in MSVS
I have two versions of Error structure in my library, so I want to use inline namespaces for the versioning.
#pragma once
#include
namespace core {
inline namespace v2 {
struct Error { // <-- new version
int…

Dalamber
- 1,009
- 1
- 12
- 32
2
votes
0 answers
How to disable populating enclosing namespaces with c++ inline namespaces in doxygen
Is there a way to disable adding inline namespaces to their enclosing namespaces in doxygen?
F.e.
Running the test example 57 with a vanilla Doxyfile created with the wizard the following class list is produced
I'm looking for a way to disable…

jesses
- 559
- 3
- 15
1
vote
1 answer
non-inline namespace cannot be reopened as inline
I'm having an issue understanding compiler's complaint:
namespace
{
}
inline namespace
{
}
gcc says
inline namespace must be specified at initial definition
and MSVC says what's in the title.
My disarray comes from my expectation that two…

v.oddou
- 6,476
- 3
- 32
- 63