mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 18:14:36 +03:00
Added cross-references.
This commit is contained in:
12
README.md
12
README.md
@@ -182,7 +182,7 @@ namespace A::B::C {
|
||||
```
|
||||
|
||||
### Structured bindings
|
||||
A proposal for de-structuring initialization, that would allow writing `auto {x, y, z} = expr;` where the type of `expr` was a tuple-like object, whose elements would be bound to the variables `x`, `y`, and `z` (which this construct declares). _Tuple-like objects_ include `std::tuple`, `std::pair`, `std::array`, and aggregate structures.
|
||||
A proposal for de-structuring initialization, that would allow writing `auto {x, y, z} = expr;` where the type of `expr` was a tuple-like object, whose elements would be bound to the variables `x`, `y`, and `z` (which this construct declares). _Tuple-like objects_ include [`std::tuple`](#tuples), `std::pair`, [`std::array`](#stdarray), and aggregate structures.
|
||||
```c++
|
||||
using Coordinate = std::pair<int, int>;
|
||||
Coordinate origin() {
|
||||
@@ -521,9 +521,9 @@ Move semantics is mostly about performance optimization: the ability to move an
|
||||
|
||||
To move an object means to transfer ownership of some resource it manages to another object. You could think of this as changing pointers held by the source object to be moved, or now held, by the destination object; the resource remains in its location in memory. Such an inexpensive transfer of resources is extremely useful when the source is an `rvalue`, where the potentially dangerous side-effect of changing the source after the move is redundant since the source is a temporary object that won't be accessible later.
|
||||
|
||||
Moves also make it possible to transfer objects such as `std::unique_ptr`s, smart pointers that are designed to hold a pointer to a unique object, from one scope to another.
|
||||
Moves also make it possible to transfer objects such as `std::unique_ptr`s, [smart pointers](#smart-pointers) that are designed to hold a pointer to a unique object, from one scope to another.
|
||||
|
||||
See the sections on: rvalue references, defining move special member functions, `std::move`, `std::forward`.
|
||||
See the sections on: [rvalue references](#rvalue-references), [defining move special member functions](#special-member-functions-for-move-semantics), [`std::move`](#stdmove), [`std::forward`](#stdforward).
|
||||
|
||||
### Rvalue references
|
||||
C++11 introduces a new reference termed the _rvalue reference_. An rvalue reference to `A` is created with the syntax `A&&`. This enables two major features: move semantics; and _perfect forwarding_, the ability to pass arguments while maintaining information about them as lvalues/rvalues in a generic way.
|
||||
@@ -539,7 +539,7 @@ auto&& al2 = x; // `al2` is an lvalue of type `int&`
|
||||
auto&& ar = 0; // `ar` is an lvalue of type `int&&`
|
||||
```
|
||||
|
||||
See also: `std::move`, `std::forward`.
|
||||
See also: [`std::move`](#stdmove), [`std::forward`](#stdforward).
|
||||
|
||||
### Variadic templates
|
||||
The `...` syntax creates a _parameter pack_ or expands one. A template _parameter pack_ is a template parameter that accepts zero or more template arguments (non-types, types, or templates). A template with at least one parameter pack is called a _variadic template_.
|
||||
@@ -612,7 +612,7 @@ add(1, 2); // == 3
|
||||
add(1, 2.0); // == 3.0
|
||||
add(1.5, 1.5); // == 3.0
|
||||
```
|
||||
The trailing return type in the above example is the _declared type_ (see section on `decltype`) of the expression `x + y`. For example, if `x` is an integer and `y` is a double, `decltype(x + y)` is a double. Therefore, the above function will deduce the type depending on what type the expression `x + y` yields. Notice that the trailing return type has access to its parameters, and `this` when appropriate.
|
||||
The trailing return type in the above example is the _declared type_ (see section on [`decltype`](#decltype)) of the expression `x + y`. For example, if `x` is an integer and `y` is a double, `decltype(x + y)` is a double. Therefore, the above function will deduce the type depending on what type the expression `x + y` yields. Notice that the trailing return type has access to its parameters, and `this` when appropriate.
|
||||
|
||||
### Lambda expressions
|
||||
A `lambda` is an unnamed function object capable of capturing variables in scope. It features: a _capture list_; an optional set of parameters with an optional trailing return type; and a body. Examples of capture lists:
|
||||
@@ -978,7 +978,7 @@ elapsed_seconds.count(); // t number of seconds, represented as a `double`
|
||||
```
|
||||
|
||||
### Tuples
|
||||
Tuples are a fixed-size collection of heterogeneous values. Access the elements of a `std::tuple` by unpacking using `std::tie` (see section), or using `std::get`.
|
||||
Tuples are a fixed-size collection of heterogeneous values. Access the elements of a `std::tuple` by unpacking using [`std::tie`](#stdtie), or using `std::get`.
|
||||
```c++
|
||||
// `playerProfile` has type `std::tuple<int, std::string, std::string>`.
|
||||
auto playerProfile = std::make_tuple(51, "Frans Nielsen", "NYI");
|
||||
|
||||
Reference in New Issue
Block a user