From 80005e1e9bab8066f02b54dd87c79a4787e303d5 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 8 Apr 2017 15:10:32 -0300 Subject: [PATCH 1/5] 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 :) --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index dbc8f8e..c1a4b90 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ C++11 includes the following new language features: - [special member functions for move semantics](#special-member-functions-for-move-semantics) - [converting constructors](#converting-constructors) - [explicit conversion functions](#explicit-conversion-functions) +- [inline-namespaces](#inline-namespaces) C++11 includes the following new library features: - [std::move](#stdmove) @@ -995,6 +996,24 @@ B b{}; if (b); // OK calls 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 From df931dfff4f835e2a3732aba17857db292d34e37 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 8 Apr 2017 15:40:22 -0300 Subject: [PATCH 2/5] Add section on non-static data member initializers Since C++11, N2756 specifies that you can initialize a non-static member on its declaration. --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c1a4b90..28650b1 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ C++11 includes the following new language features: - [converting constructors](#converting-constructors) - [explicit conversion functions](#explicit-conversion-functions) - [inline-namespaces](#inline-namespaces) +- [non-static data member initializers](#non-static-data-member-initializers) C++11 includes the following new library features: - [std::move](#stdmove) @@ -1015,6 +1016,23 @@ int oldVersion {Program::Version1::getVersion()}; // Uses getVersion() from Vers bool firstVersion {Program::isFirstVersion()}; // Does not compile when Version2 is added ``` +### Non-static data member initializers +Allows non-static data members to be initialized where they are declared, potentially cleaning up constructors of default initializations. + +```c++ +// Default initialization prior to C++11 +class Human { + Human() : age(0) {} + private: + unsigned age; +}; +// Default initialization on C++11 +class Human { + private: + unsigned age = 0; +}; +``` + ## C++11 Library Features ### std::move From 899e94e3c591c7646380744d1b32a78f84833646 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 8 Apr 2017 19:09:59 -0300 Subject: [PATCH 3/5] Update example to use uniform initialization Keeping it up to date with C++11 :) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28650b1..849c375 100644 --- a/README.md +++ b/README.md @@ -1029,7 +1029,7 @@ class Human { // Default initialization on C++11 class Human { private: - unsigned age = 0; + unsigned age{0}; }; ``` From 102599050a741282edc43c4cf4a9773f00fa94be Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 9 Apr 2017 15:43:05 -0300 Subject: [PATCH 4/5] Add improvement to usage of right angle brackets They are now properly distinguished from serializing operators (N1757). --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 849c375..53ebfa8 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ C++11 includes the following new language features: - [explicit conversion functions](#explicit-conversion-functions) - [inline-namespaces](#inline-namespaces) - [non-static data member initializers](#non-static-data-member-initializers) +- [right angle brackets](#right-angle-brackets) C++11 includes the following new library features: - [std::move](#stdmove) @@ -1033,6 +1034,15 @@ class Human { }; ``` + +### Right angle Brackets +C++11 is now able to infer when a series of right angle brackets is used as an operator or as a closing statement of typedef, without having to add whitespace. + +```c++ +typedef std::map > > cpp98LongTypedef; +typedef std::map>> cpp11LongTypedef; +``` + ## C++11 Library Features ### std::move From 0b28c2485740c85f824975d594539fda32513e00 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 9 Apr 2017 16:08:33 -0300 Subject: [PATCH 5/5] Add section about variable templates to C++14 list As per N3651 and C++14, variables can now be templated. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 53ebfa8..c88b0ae 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ C++14 includes the following new language features: - [return type deduction](#return-type-deduction) - [decltype(auto)](#decltypeauto) - [relaxing constraints on constexpr functions](#relaxing-constraints-on-constexpr-functions) +- [variable templates](#variable-templates) C++14 includes the following new library features: - [user-defined literals for standard library types](#user-defined-literals-for-standard-library-types) @@ -530,6 +531,16 @@ constexpr int factorial(int n) { factorial(5); // == 120 ``` +### Variable Templates +C++14 allows variables to be templated: + +```c++ +template +constexpr T pi = T(3.1415926535897932385); +template +constexpr T e = T(2.7182818284590452353); +``` + ## C++14 Library Features ### User-defined literals for standard library types