Title: Theory / Unimportant / CS / Programming / C++ / Manual / Norm / 07 References;
Tags: seen_description declaration todo_declaration

Name: A reference
Definition: An lvalue reference
Page: 190
Chapter: 7
Context: C++
Definition2: A const references
Conjdef: either
Definition3: A rvalue reference

Instruction: t& r {var};
Page: 187
Effect: state that r is a variable referencing the same value as var
Language: C++
Chapter: 7
Section: 4.3
Variables: t a type
t var;
Extra: Var can be replaced by lvalue ?
Name: lvalue reference

Instruction: r=foo
Page: 187
Effect: Change the value referenced by r to foo
Language: C++
Chapter: 7
Section: 4.3
Variables: t a type
t& r; a reference

Instruction: &r
Page: 187
Effect: A pointer to the the object denoted by r
Language: C++
Chapter: 7
Section: 4.3
Variables: t a type
t& r; a reference

Instruction: const t& r {expr}
Page: 187
Meaning: Similar to
const t var = (t) expr;
(const t)& r {var};
with var not used in this scope.
Language: C++
Chapter: 7
Section: 4.3
Name: const reference
Variables: t a type
expr an expression

Instruction: t&& r {expr}
Page: 187
Meaning: declare r to be a reference to the temporary expr
Language: C++
Chapter: 7
Section: 4.3
Name: rvalue reference
Variables: t a type
expr an expression
Assuming: expr an rvalue and not a lvalue
Intuition: A function taking an argument t&& r will be allowed to destroy r; it's guaranteed that r is a reference to a value that won't be used anymore after the call.
Example: If you have
int f(int&);
and
int f(int&&);
then f(x) calls the first one and f(x+4) calls the second because x+4 is a value that will disappear

Question: When can an argument of a function be a non-const reference type
Answer: When the name of the function makes it clear that it may change the values given to it
Page: 192
Chapter: 7
Section: 7.1
Context: C++ style

Question: Why can an return value of a function be a reference type
Answer: Because this way the returned value may be directly assigned to.
Page: 192
Chapter: 7
Section: 7.1
Context: C++
Example: To create a map/array, the accessor would return a reference to the element saved in the map/array, and so this can be accessed as standard array

Name: Reference collapse
Definition: the fact that a reference r1 to a reference r2 is a left-value reference if any of the two references r1 or r2 is left
Page: 196
Chapter: 7
Section: 7.3
Context: C++

Question: using U = T&
U& equals
Answer: T&
Page: 196
Chapter: 7
Section: 7.3
Context: C++

Question: using U = T&
U&& equals
Answer: T&
Page: 196
Chapter: 7
Section: 7.3
Context: C++

Question: using U = T&&
U& equals
Answer: T&
Page: 196
Chapter: 7
Section: 7.3
Context: C++

Question: using U = T&&
U&& equals
Answer: T&&
Page: 196
Chapter: 7
Section: 7.3
Context: C++

Question: When to prefere reference over pointer
Answer: If you want to be sure the name always refers to the same object
Page: 196
Chapter: 7
Section: 7.4
Context: C++
Answer2: you want to use a user-defined (overloaded) operator on something that refers to an
object.

Instruction: std::forward(x)
Page: 1028
Language: C++
Chapter: 35
Section: 4.2
Returns: x as a l/r value iff x is a left/right value
Assuming: x is not an lvalue
Intuition: perfect forwarding an argument
Exception: noexcept

Instruction: std::move_if_noexcept(x)
Page: 1028
Language: C++
Chapter: 35
Section: 4.2
Returns: if x can be moved, move(x), otherwise x
Exception: noexcept

Name: perfect forwarding
Definition: Sending an argument as a left or right reference the same way it was received
Page: 1029
Chapter: 35
Section: 4.2

Instruction: using namespace std::rel_ops;
Page: 1029
Meaning: introduce != defined using == and >, >=, <= defined using < and ==
Language: C++
Chapter: 35
Section: 5.2

Question: best practice for std::rel_ops
Answer: put it in a small namespace with the type on which you want to add relational operation, so that only this type get the extra relation
Page: 1029
Chapter: 35
Section: 5.2

Question: type_index
Answer: todo
Page: 1030
Chapter: 35
Section: 5.4