Title: Theory / Unimportant / CS / Programming / C++ / Manual / Norm / 08 Structures;
Tags: declaration todo_declaration FromInstruction computer_to_instruction hasNotNewEffectReturnsMeaning syntactical_sugar

Instruction: struct foo{
  bar
};
Page: 202, 454
Meaning: same as
class foo {
 public:
  bar
}
Language: C++
Chapter: 8, 16
Section: 2, 2.4
Intuition: Usually used as simply a bunch of data with very simple members

Instruction: foo plop ={
miam_1,
...,
miam_n
}
Page: 202
Effect: If foo has no constructor:-Assign a structure of type foo to variable plop where bar_i's value is miam_i
otherwise:
-call the constructor with parameters miam1,
...,
miamn
Language: C++
Chapter: 8
Section: 2
Variables: struct foo{
t_1 bar_1;
_ ...
t_n bar_n;
};

Instruction: (*foo).bar
Page: 202
Language: C++
Chapter: 8
Section: 2
Abbreviation: foo->bar

Instruction: foo.bar_i
Page: 202
Language: C++
Chapter: 8
Section: 2
Returns: the value of the parameter bar_i in foo
Variables: struct foo{
t_1 bar_1;
_ ...
t_n bar_n;
};
miam of type foo

Question: How is saved a struct in memory
Answer: the position of the i+1-th element, of size n, is the least multiple of n in memory which occur after the end of the position of the i-th element
Page: 204
Chapter: 8
Section: 2
Context: C++ standard

Question: How to create efficient struct
Answer: Ensure that there is no hole by reordering elements such that some value of size n start at a position multiple of n
Page: 204
Chapter: 8
Section: 2
Context: C++ standard

Question: When can the name of a struct be used
Answer: After it has been encountered, even if the declaration is not entirely done
Page: 204
Chapter: 8
Section: 2.2
Context: C++ standard

Question: When can a struct be used
Answer: After its actual declaration has been given
Page: 205
Chapter: 8
Section: 2.2
Context: C++ standard

Instruction: struct foo;
Page: 205
Meaning: Declare that foo is a type referring to a structure, without giving yet its meaning
Language: C++
Chapter: 8
Section: 2.2

Question: What to do when a struct name foo is overloaded (i.e. also used as the name of a non-struct)
Answer: Use (struct foo) instead of foo
Page: 205
Chapter: 8
Section: 2.2
Context: C++ standard

Name: A struct
Definition: A class with members public by default
Page: 205, 453
Chapter: 8
Section: 2.2
Context: C++ standard

Question: What happens when a struct is cast in another identical structure of different name
Answer: error
Page: 210
Chapter: 8
Section: 2.5
Context: C++ standard

Instruction: enum Foo {name_0, .., name_n}
Page: 67, 222
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, 8 manual
Section: 10, 4.2
Name: enum
Intuition: present in all code before enum class. Avoid in modern c++ as it polute namespace

Instruction: std::is_pod<T>::value
Page: 784
Language: C++
Chapter: 28
Section: 2.2
Returns: whether T is a plain old data structure

Name: Plain old data
Definition: a standard layout type
Page: 211
Chapter: 8
Section: 2.6
Context: C++
Definition2: a trivially copyable type,
Conjdef: An object with
Definition3: a type with a trivial default constructor.
Intuition: an object that can be manipulated as ‘‘just data’’ without worrying about complications

Name: A trivial type
Definition: a trivial default constructor and
Page: 211
Chapter: 8
Section: 2.6
Context: C++
Definition2: trivial copy and move operations
Conjdef: A type with

Name: A type with standard layout
Definition: a non-static member not in standard layout
Page: 211
Chapter: 8
Section: 2.6
Context: C++
Definition2: a base not in standard layout
Conjdef: A type without
Definition3: a virtual function
Intuition: has a layout with an obvious equivalent in C and is in
the union of what common C++ Application Binary Interfaces (ABIs) can handle
Definition4: a virtual base
Definition5: a member that is a reference
Definition6: has multiple access specifiers for non-static data members
Definition7: having non- static data members in more than one base class or in both the derived
class and a base
Definition8: having a base class of the same type as the first non- static data membe

Name: A type which is trivially copyable
Definition: virtual function
Page: 211
Chapter: 8
Section: 2.6
Context: C++
Definition2: virtual base
Conjdef: A type without
Definition3: a base which is not trivially copyable
Definition4: copy, move or destructor which are user-defined

Instruction: some_integral_type name : number_of_bit;
Page: 212
Meaning: Introduce name as a member of type some_integral_type taking exactly number_of_bit.
Language: C++
Chapter: 8
Section: 2.7
Name: a field

Question: What is the advantage of a field over a member
Answer: it saves run-time space. E.g. one bit by boolean instead of one byte
Page: 212
Chapter: 8
Section: 2.7
Context: C++

Question: What is the advantage of a member over a field
Answer: No need to explicitly mention how much space is used
Page: 212
Chapter: 8
Section: 2.7
Context: C++
Answer2: you can take a reference to a member, not to a field
Answer3: simpler access to a member (since it is an entire byte, aligned with memory). Hence quicker and less code generated

Typ: union {
  t_1 var_1;
  ...
  t_n var_n;
}
Meaning: A struct with members var_i of type t_i, but containing exactly one assigned values
Page: 213, 216
Language: C++
Chapter: 8
Section: 2.7
Intuition: std::variant before c++ 17
Space complexity: max(size of t_i | 0<i<n+1)

Question: constraints on union
Answer: It can not have virtual functions
Page: 215
Chapter: 8
Section: 3.1
Context: C++
Answer2: can not have members of reference type
Answer3: cannot have base classes
Answer4: the member user-defined constructor, copy, move and destructor are deleted for that union
Answer5: At most one member can have an in-class initializer
Answer6: cannot be used as a base class

Instruction: union Name {
  t_1 var_1;
  ...
  t_n var_n;
}
Page: 215
Meaning: represents the union
Language: C++
Chapter: 8
Section: 3.1
Identifier: Name
Similar to: union {
  t_1 var_1;
  ...
  t_n var_n;
}

Instruction: union_name var
Page: 215
Effect: var is a union_name with default initializer
Language: C++
Chapter: 8
Section: 3.1
Variables: union union_name {
  t_1 var_1;
  ...
  t_n var_n;
}
Assuming: one member has a default initializer

Instruction: union_name var {args}
Page: 215
Effect: var is a union_name, with var_i set for i with t_i  {args} defined
Language: C++
Chapter: 8
Section: 3.1
Variables: union union_name {
  t_1 var_1;
  ...
  t_n var_n;
}

Name: A tagged union
Definition: A struct that is mostly a union, plus a tag to note which field of the union is set, and accessor/setter for the union
Page: 217
Chapter: 8
Section: 3.1
Name2: A discrimated union

Instruction: enum class Foo : integral_type {foo}
Page: 218
Meaning: same as enum class Foo {foo}, with values encoded in integral_type
Language: C++
Chapter: 8
Section: 4

Instruction: enum {name_0, ..., name_n}
Page: 224
Meaning: introduce name_0, ..., name_n in current scope with distinct integral values, do not introduce type with it
Language: C++
Chapter: 8
Section: 4.3