Title: Theory / Unimportant / CS / Programming / C++ / Effective modern / 03 moving to modern
Tags: declaration todo_declaration

Question: What are the different way to call a constructor of class Foo
Answer: Foo var_name (default constructor)
Page: 49
Chapter: 3
Section: 7
Answer2: Foo var_name(args)
Answer3: Foo var_name = Foo(args)
Answer4: Foo var_name{args}
Answer5: Foo var_name = {args}
Answer6: Foo var_name = another_foo; (Copy constructor)

Name: most vexing parse
Definition: When an expression is ambiguous and can be declared as a function declaration, it should be interpreted as such
Page: 50
Chapter: 3
Section: 7
Context: C++
Example: Foo w();
It is intended as variable w of type widget with an empty constructor,
but it's parsed a function with no argument returning a Foo

Question: What's the difference between NULL and nullptr
Answer: nullptr is a pointer. NULL is an integral type
Page: 58
Chapter: 3
Section: 8
Context: C++

Question: What should you do when you define a method taking an integral type as one of the argument
Answer: Do not override it with taking a pointer as the same argument. Otherwise, calling with NULL will use the first one and the caller expect the second one
Page: 58
Chapter: 3
Section: 8
Context: C++

Question: What should you do when you define a method taking a pointer as one of the argument
Answer: Do not override it with taking an integral type as the same argument. Otherwise, calling with NULL will use the first one and the caller expect the second one
Page: 58
Chapter: 3
Section: 8

Instruction: Foo var_name(args);
Effect: var_name get assigned the result of applying args to Foo constructor; using same type matching as function
Language: c++
Chapter: 3
Section: 7

Instruction: Foo var_name;
Effect: var_name get assigned the result of the default Foo constructor
Language: c++
Chapter: 3
Section: 7

Instruction: Foo var_name();
Meaning: define a function var_name taking no argument and returning Foo.
Language: c++
Chapter: 3
Section: 7
Intuition: (Usually a bug)

Instruction: Foo var_name{};
Effect: var_name get assigned the result of Foo with the empty constructor
Language: c++
Chapter: 3
Section: 7

Instruction: Foo var_name{{}};Foo var_name({});
Effect: var_name get assigned the result of Foo with input an empty initializer_list
Language: c++
Chapter: 3
Section: 7
Extra: Foo var_name{} would not work

Instruction: Foo var_name = {arg_1,..., arg_n};
Effect: var_name get assigned:
* the result of Foo with input an initializer_list with content arg_1,..., arg_n if it exists.
* Otherwise, call the constructor of Foo with arguments compatible with arg_1,..., arg_n's type, same rule for decision as function
Language: c++
Chapter: 3
Section: 7
Variables: n>0
Abbreviation: Foo var_name{arg_1,..., arg_n};
Extra: even if there is better typing for

Instruction: Foo var_name = expr
Effect: var_name get assigned to the result of the copy constructor taking expr as input
Language: c++
Chapter: 3
Section: 7
Extra: even if there is better typing for

Instruction: var_name = expr
Effect: call the = operator of var_name
Language: c++
Chapter: 3
Section: 7
Variables: Foo var_name
Extra: even if there is better typing for

Name: An alias template
Definition: An alias (using type_var = aliased_type) which is templatized
Page: 63
Chapter: 3
Section: 9

Instruction: typename type
Page: 63
Effect: same as type, but guarantiing that type is understood as a type and not a variable
Language: C++
Chapter: 3
Section: 9

Instruction: enum class Foo {value_1, .., value_n}
Page: 67, 219
Meaning: Introduce in the scope a type Foo and all of its values are
Foo::value_1, ... and Foo:: value_n
Language: C++
Chapter: 3 modern, 8 manual
Section: 10, 4.1
Name: enum class

Instruction: enum Foo {name_0 = value_0, .., name_n = value_n}
Page: 67, 220
Meaning: Introduce in the scope an integral type Foo and all of its values are
name_0 with value_0, ... and name_n with value_n
Language: C++
Chapter: 3 moden, 8 manual
Section: 10, 4.1

Question: What are the pros of "enum" instead of "enum class"
Answer: If you actually want to use enum as an integral value. E.g. to indicate the position in a tuple
Page: 71
Chapter: 3
Section: 10

Question: What are the pros of "enum class" instead of "enum"
Answer: avoid to pollute namespace
Page: 71
Chapter: 3
Section: 10
Context: C++
Answer2: avoid implicit conversion between enum and numeric type, ensuring type savefy

Question: What are the use of "= delete" compared to making a function private unimplemented
Answer: a private unimplemented function can still be used by friend class and other member
Page: 75
Chapter: 3
Section: 11
Answer2: private can be called by other member and friends

Instruction: function_decl = delete
Page: 75
Meaning: Ensure that call to the function declared by function_decl will lead to compilation error
Language: C++
Chapter: 3
Section: 11

Question: what are the use of = delete
Answer: If your function take an int, making a similar definition with char, double, etc... = delete will ensure that it will only accept int and no implicit conversion
Page: 75, 524
Chapter: 3, 17
Section: 11, 6
Answer2: during inheritance, it allow to remove methods in child class
Answer3: in template instantiation, ensure that some methods are not used for some spefic instantiation
Answer4: Ensure that a class is not used as local variable by deleting its destructor

Question: What are the condition allowing overriding
Answer: The base class function must be virtual.
Page: 80
Chapter: 3
Section: 11
Answer2: The base and derived function names must be identical (except in the case of
destructors).
Answer3: The parameter types of the base and derived functions must be identical.
Answer4: The constness of the base and derived functions must be identical.
Answer5: The return types and exception specifications of the base and derived functions must be compatible.
Answer6: The functions’ reference qualifiers must be identical (C++11 and later)

Instruction: function_declaration override
Page: 82
Meaning: same as function_declaration
Also, compiler fail if function_declaration is not overriding another method
Language: C++
Chapter: 3
Section: 11
Intuition: Allow to detect when an override which is expected will afil

Instruction: virtual function_declaration
Page: 82
Meaning: same as function_declaration
Also, in classes inheriting the current class, overriding function_declaration, the new declaration will be used
Language: C++
Chapter: 3
Section: 11

Instruction: final function_declaration
Page: 82
Meaning: same as function_declaration
Also, this function can not be overriden
Language: C++
Chapter: 3
Section: 11

Instruction: final class_declaration
Page: 82
Meaning: same as class_declaration
Also, this class can not be inherited
Language: C++
Chapter: 3
Section: 11

Instruction: class_declaration noexcept
class_declaration throw() deprecated
Page: 90
Meaning: same as class_declaration
Also, this function guarantee not to throw any exception
Language: C++
Chapter: 3
Section: 14

Question: What is the advantage of noexcept
Answer: optimizers need
not keep the runtime stack in an unwindable state if an exception would propagate
out of the function, nor must they ensure that objects in a noexcept function are
destroyed in the inverse order of construction should an exception leave the function.
Page: 91
Chapter: 3
Section: 14
Answer2: std::move_if_noexcept allow to replace copy by move when the move operator is noexcept and it is safe to do so.
E.g. in order to copy an array to a bigger array, without risking loosing current values, the copy can be done with move if it is known no exception can occur, otherwise with copy.

Name: An exception neutral function
Definition: A function which may throw an exception only if its underlying type may throw an exception
Page: 93
Chapter: 3
Section: 14
Example: swapping array is exception neutral, because it can throws an exception only if swapping elements of the array can throw an exception

Name: A wide contract
Definition: A function with no precondition
Page: 95
Chapter: 3
Section: 14

Name: A narrow contract
Definition: A function with precondition
Page: 95
Chapter: 3
Section: 14
Example: length is < 32.

Instruction: function_declaration noexcept(foo)
Page: 93
Meaning: Same as function_declaration
is noexcept if foo holds.
Language: C++
Chapter: 3
Section: 14
Name: A conditionally noexcept function

Instruction: noexcept(foo)
Page: 95
Language: C++
Chapter: 3
Section: 14
Returns: Whether foo is noexcept. Do not execute foo

Question: When not to use constexpr
Answer: When you do not want to guarantee that future version will be constexpr. As it may break code
Page: 102
Chapter: 3
Section: 15

Question: How to decide between mutexes and atomic
Answer: atomic for a single variable, otherwise mutex
Page: 107
Chapter: 3
Section: 16

Name: A special member function
Definition: A function that C++ is willing to generate on its own
Page: 109, 517
Chapter: 3, 17
Section: 17, 6
Example: default constuctor, destructor, copy constructor, copy assignment operator
Example2: move constructor, move assignment operator
Applied to: in C++98
Applied to2: in C++11, also

Question: What are the condition for a generating automatically a move operation
Answer: No other move assignment should be explicitly defined
Page: 110
Chapter: 3
Section: 17
Answer2: No copy operation is explicitly generated
Answer3: no destructor is explicitly defined

Question: What are the condition for a generating automatically a copy operation
Answer: No move assignment should be explicitly defined
Page: 110
Chapter: 3
Section: 17
Extra: it's acceptable to have another copy operation explicitly defined

Smaller0: the copy constructor is explicitly defined
Greater0: the copy operator is explicitly defined
Page: 111
Chapter: 3
Section: 17
Smaller to greater: iff
Name: The rule of three
Intermediate: the destructor is explicitly defined

Instruction: ~Foo() = default;
Page: 112
Effect: Class Foo uses the default destructor
Language: C++
Chapter: 3
Section: 17

Instruction: Foo(const Foo&) = default;
Page: 112
Meaning: Class Foo uses the default copy constructor
Language: C++
Chapter: 3
Section: 17

Instruction: Foo& operator=(const Foo&) = default;
Page: 112
Meaning: Class Foo uses the default copy assignment
Language: C++
Chapter: 3
Section: 17

Instruction: Foo& operator=(const Foo&&) = default;
Page: 112
Meaning: Class Foo uses the default move assignment
Language: C++
Chapter: 3
Section: 17

Instruction: Foo(const Foo&&) = default;
Page: 112
Meaning: Class Foo uses the default move constructor
Language: C++
Chapter: 3
Section: 17

Question: In which case is the default constructor automatically generated
Answer: if no other constructor is generated
Page: 114
Chapter: 3
Section: 17