Add section about inline namespaces

As suggested on issue #15, inline namespaces were missing from the documentation, so I added a sentence with a snippet :)
This commit is contained in:
Tulio Leao
2017-04-08 15:10:32 -03:00
committed by GitHub
parent a3c8e41cd2
commit 80005e1e9b

View File

@@ -63,6 +63,7 @@ C++11 includes the following new language features:
- [special member functions for move semantics](#special-member-functions-for-move-semantics) - [special member functions for move semantics](#special-member-functions-for-move-semantics)
- [converting constructors](#converting-constructors) - [converting constructors](#converting-constructors)
- [explicit conversion functions](#explicit-conversion-functions) - [explicit conversion functions](#explicit-conversion-functions)
- [inline-namespaces](#inline-namespaces)
C++11 includes the following new library features: C++11 includes the following new library features:
- [std::move](#stdmove) - [std::move](#stdmove)
@@ -995,6 +996,24 @@ B b{};
if (b); // OK calls B::operator bool() if (b); // OK calls B::operator bool()
bool bb = b; // error copy-initialization does not consider B::operator bool() bool bb = b; // error copy-initialization does not consider B::operator bool()
``` ```
### Inline namespaces
All members of an inline namespace are treated as if they were part of its parent namespace, allowing specialization of functions and easing the process of versioning. This is a transitive property, if A contains B, which in turn contains C and both B and C are inline namespaces, C's members can be used as if they were on A.
```c++
namespace Program {
namespace Version1 {
int getVersion() { return 1; }
bool isFirstVersion() { return true; }
}
inline namespace Version2 {
int getVersion() { return 2; }
}
}
int version {Program::getVersion()}; // Uses getVersion() from Version2
int oldVersion {Program::Version1::getVersion()}; // Uses getVersion() from Version1
bool firstVersion {Program::isFirstVersion()}; // Does not compile when Version2 is added
```
## C++11 Library Features ## C++11 Library Features