Title: Theory / Unimportant / CS / Programming / C++ / STL / variant
Tags: automatedNewLineAfterCommaSpace constant
On every note of this deck, unless a note says otherwise:
Page: https://en.cppreference.com/w/cpp/utility/variant

Typ: std::variant<T1, ..., Tn>
Meaning: A structure containing a value of type T1, ..., or Tn (except in case of error)
Page: https://en.cppreference.com/w/cpp/utility/variant
Language: C++
Assuming: not permitted to hold references, arrays, or the type void
Space complexity: max ({space(Ti)|0<i<=n})

Constant: variant_npos
Meaning: the index representing a variant in error state
Page: https://en.cppreference.com/w/cpp/utility/variant
Language: c++
Context: variant

Instruction: variant.index()
Language: c++
Returns: the index of the variant, or variant_npos in case of error
Variables: std::variant<T1, ..., Tn> variant;
Exception: noexcept

Instruction: variant.valueless_by_exception()
Language: c++
Returns: whether the variant contains no value
Variables: std::variant<T1, ..., Tn> variant;
Exception: noexcept

Instruction: std::variant<T1, ..., Tn>()
Language: c++
Returns: the variant with value T1() if it is defined, otherwise ill-formed
Exception: noexcept

Instruction: std::variant<T1, ..., Tn>(args)
Language: c++
Returns: the variant with value Ti(args) with some complex rule to determine which Ti to choose.
Assuming: (avoid in case of any ambiguity)

Instruction: std::variant<T1,
  ...,
  Tn>(
  i,
  args
)
Language: c++
Returns: the variant with value Ti(  args)
Assuming: (
  avoid in case of any ambiguity
)

Instruction: variant.emplace<i>(args)
Effect: Destroy value of variant and replace it by Ti(args)
Language: c++
Variables: std::variant<T1, ..., Tn> variant

Instruction: holds_alternative<Ti>(variant)
Language: c++
Returns: whether variant contains the alternative Ti
Variables: std::variant<T1, ..., Tn> variant
Assuming: Ti appear exactly once

Instruction: std::get<Ti>(variant)
Language: c++
Returns: the value contained in the variant, assuming it is Ti
Variables: std::variant<T1, ..., Tn> variant
Assuming: Ti appear exactly once
Exception: std::bad_variant_access if it does not contain a value of type Ti

Instruction: std::get<i>(variant)
Language: c++
Returns: the value contained in the i-th variant
Variables: std::variant<T0, ..., Tn> variant
Exception: std::bad_variant_access if it does not contain a value of the i-th variant

Instruction: std::get_if<i>(variant)
Language: c++
Returns: pointer to the value contained in the i-th variant if variant contains such a value, nullptr otherwise
Variables: std::variant<T0, ..., Tn> variant

Instruction: std::get_if<Ti>(variant)
Language: c++
Returns: pointer to the value contained in the Ti variant if variant contains such a value, nullptr otherwise
Variables: std::variant<T0, ..., Tn> variant
Assuming: Ti appear exactly once

Question: Order over std::variant<T0, ..., Tn>
Answer: valueless_by_exception is smallest
Page: https://en.cppreference.com/w/cpp/utility/variant
Context: C++
Answer2: sorted by index otherwise
Answer3: sorted according to underlying value if they have the same index

Typ: std::monostate
Meaning: A type with a single value
Page: https://en.cppreference.com/w/cpp/utility/variant/monostate
Language: C++
Intuition: Allow variant to have a non erroneous constructible non-value