Title: Theory / Unimportant / CS / Programming / C++ / Effective modern / 01 types
Tags: automatedNewLineAfterCommaSpace

Question: In
template<typename T>
void f(ParamType_of_T& param);
f(expr);
how is T determined
Answer: If expr is a reference type, ignore the reference part
Page: 11
Chapter: 1
Context: c++
Answer2: Param_type_of_T should have the same type as expr.
Use it to find the type of T

Question: In
template<typename T>
void f(const ParamType_of_T& param);
f(expr);
how is T determined
Answer: If expr's type is const E, match E with ParamType_of_T
Page: 11
Chapter: 1
Context: c++
Answer2: otherwise, if expr's type is not constant, match its type with ParamType_of_T

Typ: foo (&)[n]
Meaning: reference to an array of foo of size n
Page: 14
Language: C++
Chapter: 1
Section: 2

Typ: foo (&)[]
Meaning: reference to an array of foo
Page: 16
Language: C++
Chapter: 1
Section: 2

Typ: std::initializer_list<T>
Meaning: A list of arguments of type T used to initialize some variable.
Page: 21
Language: C++
Chapter: 1
Section: 2
Intuition: type returned for an auto variable initialized with {}

Instruction: auto funName(
  t_1 param_1,
  ...,
  t_n param_n
) -> foo {
  body
}
Page: 21
Effect: Same as
foo funName(t_1 param_1, ..., t_n param_n) {
  body
}
Except that foo can depends of the parameters to decide its type. E.g. using decltype
Language: C++
Chapter: 1
Section: 2

Typ: auto
Meaning: type guessed by context. Not a reference and not const, instead assume we expect to copy/move the value
Page: 26
Language: C++
Chapter: 1
Section: 2

Typ: decltype(auto)
Meaning: type guessed by context, keeping reference, constness
Page: 26
Language: C++
Chapter: 1
Section: 2

Instruction: (x)
Page: 29
Language: C++
Chapter: 1
Section: 2
Returns: reference to x
Intuition: Only relevant when use with decltype

Question: Advantage of using auto
Answer: Less verbosity,
Page: 37, 38,  39, 40
Chapter: 2
Section: 5
Context: C++
Answer2: auto variable takes less memory than std::function<> (why?)
Answer3: allow to use type internal to compiler that you could not write explicity
Answer4: ensure proper initialization of variable (otherwise, auto can't work)
Answer5: Avoid useless conversion that would only occur because the developer did not put the proper type when declaring a variable.
E.g. forgetting a const, which lead to copy of reference.
E.g. using unsigned instead of `std::vector<int>::size_type`, which is valid on 32 bit machine and not on 64 bit machine
Answer6: `auto x = f()` always use the correct type, even if `f`'s return type is updated (e.g. from int to long)

Question: How to deal with the fact that `auto` removes the typing hint you get when you read the code
Answer: You can use explicit typing if really necessary
Page: 42
Chapter: 2
Section: 5
Answer2: Usually, IDE can give you the inferred type
Answer3: Use explicit variable name

Name: A proxy class
Definition: A class that exists for the purpose of emulating and augmenting the behavior of some other type
Page: 45
Chapter: 2
Section: 6
Example: std::vector<bool>::reference simulate `bool &` whose boolean is in a vector
Example2: std::shared_ptr is a proxy for ap ointer

Name: A visible proxy class
Definition: A proxy class whose type is explicitly used by the developer.
Page: 45
Chapter: 2
Section: 6
Example: std::shared_ptr

Name: An invisible proxy class
Definition: A proxy class whose type is not expected to be used explicitly. Instead, its value should be used directly or converted to the type it is a proxy for
Page: 45
Chapter: 2
Section: 6
Example: std::vector<bool>::reference should be used directly or converted to bool
Intuition: objects whose life is not supposed to be longer than a single statement. Don't use auto

Question: How to detect proxy classes
Answer: Look at return type of library function
Page: 46
Chapter: 2
Section: 6
Answer2: find them while investigating compilation or test error

Instruction: static_cast<type>(expr)
Page: 47
Language: C++
Chapter: 2
Section: 6
Returns: expr but as type type
Exception: if cast is impossible

Question: When should you use static_cast
Answer: To indicate explicitly a type change (e.g. doubte to change)
Page: 47
Chapter: 2
Section: 6
Answer2: to use with auto to force it to have the right type (todo: why use auto in this case?)
Answer3: In function call, to ensure the correct version of the function is called

Question: In `f((U&) var);` how is `U&` and T matched?
Answer: Match U and T (ignore the reference)
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template

Question: In `f((volatile U) var);` how is `volatile U` and T matched?
Answer: Match U and T (ignore volatile)
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template

Question: In `f((const U) var);` how is `const U` and T matched?
Answer: Match U and T (ignore const)
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template

Question: In `f((U[]) var);` how is U[] and T matched?
Answer: Match U* and T (use pointer instead of array)
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template

Question: In `f(some_fn);` how is the type of some_fn and T matched?
Answer: Match the pointer to some_fn and T (use pointer function instead of function itself)
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template

Question: In
```
U var;
f(var);
```
with U having no reference, volatile, const, foo[], not being a function, how is U and T matched?
Answer: Match U and T directly (todo: more specific?)
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template

Question: In `f((U&&) var);` how is `U&&` and T matched?
Answer: match U and T
Page: 14
Chapter: 1
Section: 2
Variables: template<typename T>
void f(ParamType(T) param);
Context: C++ template