mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 10:34:35 +03:00
Fix minor formatting issues
Changed the order of the title to reflect the actual order of the text and fixed some minor formatting on the text :)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# C++11/14/17
|
# C++17/14/11
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
Many of these descriptions and examples come from various resources (see [Acknowledgements](#acknowledgements) section), summarized in my own words.
|
Many of these descriptions and examples come from various resources (see [Acknowledgements](#acknowledgements) section), summarized in my own words.
|
||||||
@@ -515,7 +515,7 @@ static_assert(std::is_same<const int&, decltype(g(x))>::value == 1);
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Relaxing constraints on constexpr functions
|
### Relaxing constraints on constexpr functions
|
||||||
In C++11, `constexpr` function bodies could only contain a very limited set of syntax, including (but not limited to): `typedef`s, `using`s, and a single `return` statement. In C++14, the set of allowable syntax expands greatly to include the most common syntax such as `if` statements, multiple `return`s, loops, etc.
|
In C++11, `constexpr` function bodies could only contain a very limited set of syntaxes, including (but not limited to): `typedef`s, `using`s, and a single `return` statement. In C++14, the set of allowable syntaxes expands greatly to include the most common syntax such as `if` statements, multiple `return`s, loops, etc.
|
||||||
```c++
|
```c++
|
||||||
constexpr int factorial(int n) {
|
constexpr int factorial(int n) {
|
||||||
if (n <= 1) {
|
if (n <= 1) {
|
||||||
@@ -676,7 +676,7 @@ addX(1); // == 2
|
|||||||
auto getXRef = [&]() -> int& { return x; };
|
auto getXRef = [&]() -> int& { return x; };
|
||||||
getXRef(); // int& to `x`
|
getXRef(); // int& to `x`
|
||||||
```
|
```
|
||||||
By default value-captures cannot be modified inside the lambda because the compiler-generated method is marked as `const`. The `mutable` keyword allows modifying captured variables. The keyword is placed after the parameter-list (which must be present even if it is empty).
|
By default, value-captures cannot be modified inside the lambda because the compiler-generated method is marked as `const`. The `mutable` keyword allows modifying captured variables. The keyword is placed after the parameter-list (which must be present even if it is empty).
|
||||||
```c++
|
```c++
|
||||||
int x = 1;
|
int x = 1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user