libdonut
2.3.2
Application framework for cross-platform game development in C++20
|
Tagged union value type that holds a value of one of the given types. More...
#include <donut/Variant.hpp>
Public Types | |
using | index_type = std::conditional_t< sizeof...(Ts)< 255ull, std::uint8_t, std::conditional_t< sizeof...(Ts)< 65535ull, std::uint16_t, std::conditional_t< sizeof...(Ts)< 4294967295ull, std::uint32_t, std::uint64_t > >> |
Index type used to encode the active alternative type. More... | |
Public Member Functions | |
constexpr | Variant () noexcept(std::is_nothrow_default_constructible_v< variant_alternative_t< 0, Variant >>) requires(HAS_DEFAULT_CONSTRUCTOR) |
Default-construct a variant with the first variant alternative, if it is default-constructible. More... | |
template<typename U > | |
constexpr | Variant (U &&value) noexcept(std::is_nothrow_constructible_v< decltype(F(std::forward< U >(value)))>) requires(!std |
Converting constructor. More... | |
template<typename T , typename... Args> | |
constexpr | Variant (std::in_place_type_t< T > type, Args &&... args) requires(variant_has_alternative_v< T |
Construct a variant alternative in-place given its type. More... | |
constexpr Variant | std::forward (args)...) |
template<typename T , typename U , typename... Args> | |
constexpr | Variant (std::in_place_type_t< T > type, std::initializer_list< U > ilist, Args &&... args) requires(variant_has_alternative_v< T |
Construct a variant alternative in-place given its type, with an initializer list as the first constructor argument. More... | |
constexpr Variant | std::forward (args)...) |
template<std::size_t Index, typename... Args> | |
constexpr | Variant (std::in_place_index_t< Index > index, Args &&... args) requires(Index< sizeof...(Ts) &&std |
Construct a variant alternative in-place given its index. More... | |
template<std::size_t Index, typename U , typename... Args> | |
constexpr | Variant (std::in_place_index_t< Index > index, std::initializer_list< U > ilist, Args &&... args) requires(Index< sizeof...(Ts) &&std |
Construct a variant alternative in-place given its index, with an initializer list as the first constructor argument. More... | |
constexpr | ~Variant () |
Destructor. More... | |
constexpr | ~Variant () requires(HAS_TRIVIAL_DESTRUCTOR)=default |
Trivial destructor. More... | |
constexpr | Variant (const Variant &other) requires(!HAS_COPY_CONSTRUCTOR)=delete |
Deleted copy constructor. More... | |
constexpr | Variant (const Variant &other) requires(HAS_COPY_CONSTRUCTOR &&HAS_TRIVIAL_COPY_CONSTRUCTOR)=default |
Trivial copy constructor. More... | |
constexpr | Variant (const Variant &other) requires(HAS_COPY_CONSTRUCTOR &&!HAS_TRIVIAL_COPY_CONSTRUCTOR) |
Copy constructor. More... | |
constexpr | Variant (Variant &&other) noexcept requires(HAS_MOVE_CONSTRUCTOR &&HAS_TRIVIAL_MOVE_CONSTRUCTOR)=default |
Trivial move constructor. More... | |
constexpr | Variant (Variant &&other) noexcept((std::is_nothrow_move_constructible_v< Ts > &&...)) requires(HAS_MOVE_CONSTRUCTOR &&!HAS_TRIVIAL_MOVE_CONSTRUCTOR) |
Move constructor. More... | |
constexpr Variant & | operator= (const Variant &other) requires(!HAS_COPY_ASSIGNMENT)=delete |
Deleted copy assignment. More... | |
constexpr Variant & | operator= (const Variant &other) requires(HAS_COPY_ASSIGNMENT &&HAS_TRIVIAL_COPY_ASSIGNMENT)=default |
Trivial copy assignment. More... | |
constexpr Variant & | operator= (const Variant &other) requires(HAS_COPY_ASSIGNMENT &&!HAS_TRIVIAL_COPY_ASSIGNMENT) |
Copy assignment. More... | |
constexpr Variant & | operator= (Variant &&other) noexcept requires(HAS_MOVE_ASSIGNMENT &&HAS_TRIVIAL_MOVE_ASSIGNMENT)=default |
Trivial move assignment. More... | |
constexpr Variant & | operator= (Variant &&other) noexcept(((std::is_nothrow_move_constructible_v< Ts > &&//NOLINT(performance-noexcept-move-constructor, cppcoreguidelines-noexcept-move-operations) std::is_nothrow_move_assignable_v< Ts >)&&...)) requires(HAS_MOVE_ASSIGNMENT &&!HAS_TRIVIAL_MOVE_ASSIGNMENT) |
Move assignment. More... | |
template<typename U > | |
constexpr Variant & | operator= (U &&value) noexcept(std::is_nothrow_assignable_v< decltype(F(std::forward< U >(value)))&, U > &&std::is_nothrow_constructible_v< decltype(F(std::forward< U >(value))), U >) requires(!std |
Converting assignment. More... | |
template<typename T , typename... Args> | |
constexpr T & | emplace (Args &&... args) requires(variant_has_alternative_v< T |
Construct an alternative given its type, destroying the old value. More... | |
template<typename T , typename U , typename... Args> | |
constexpr T & | emplace (std::initializer_list< U > ilist, Args &&... args) requires(variant_has_alternative_v< T |
Construct an alternative given its type, with an initializer list as the first constructor argument, destroying the old value. More... | |
template<std::size_t Index, typename... Args> | |
constexpr variant_alternative_t< Index, Variant > & | emplace (Args &&... args) requires(std |
Construct an alternative given its index, destroying the old value. More... | |
template<std::size_t Index, typename U , typename... Args> | |
constexpr variant_alternative_t< Index, Variant > & | emplace (std::initializer_list< U > ilist, Args &&... args) requires(std |
Construct an alternative given its index, with an initializer list as the first constructor argument, destroying the old value. More... | |
constexpr void | swap (Variant &other) noexcept(((std::is_nothrow_move_constructible_v< Ts > &&std::is_nothrow_swappable_v< Ts >)&&...)) |
Swap this variant's value with that of another. More... | |
constexpr index_type | index () const noexcept |
Get the alternative index of the currently active value held by the variant. More... | |
constexpr bool | valueless_by_exception () const noexcept |
Check if the variant is in the valueless by exception state. More... | |
template<typename T > | |
constexpr bool | is () const noexcept requires(variant_has_alternative_v< T |
Check if the variant currently holds the alternative with the given type. More... | |
template<std::size_t Index> | |
constexpr bool | is () const noexcept |
Check if the variant currently holds the alternative with the given index. More... | |
template<typename T > | |
constexpr T & | as () &noexcept requires(variant_has_alternative_v< T |
Access the underlying value with the given type without a safety check. More... | |
return | as () |
template<typename T > | |
constexpr const T & | as () const &noexcept requires(variant_has_alternative_v< T |
Access the underlying value with the given type without a safety check. More... | |
return | as () |
template<typename T > | |
constexpr T && | as () &&noexcept requires(variant_has_alternative_v< T |
Access the underlying value with the given type without a safety check. More... | |
return | std::move (as< variant_index_v< T, Variant >>()) |
template<typename T > | |
constexpr const T && | as () const &&noexcept requires(variant_has_alternative_v< T |
Access the underlying value with the given type without a safety check. More... | |
return | std::move (as< variant_index_v< T, Variant >>()) |
template<std::size_t Index> | |
constexpr variant_alternative_t< Index, Variant > & | as () &noexcept |
Access the underlying value with the given index without a safety check. More... | |
template<std::size_t Index> | |
constexpr const variant_alternative_t< Index, Variant > & | as () const &noexcept |
Access the underlying value with the given index without a safety check. More... | |
template<std::size_t Index> | |
constexpr variant_alternative_t< Index, Variant > && | as () &&noexcept |
Access the underlying value with the given index without a safety check. More... | |
template<std::size_t Index> | |
constexpr const variant_alternative_t< Index, Variant > && | as () const &&noexcept |
Access the underlying value with the given index without a safety check. More... | |
template<typename T > | |
constexpr T & | get () &requires(variant_has_alternative_v< T |
Access the underlying value with the given type. More... | |
template<typename T > | |
constexpr const T & | get () const &requires(variant_has_alternative_v< T |
Access the underlying value with the given type. More... | |
template<typename T > | |
constexpr T && | get () &&requires(variant_has_alternative_v< T |
Access the underlying value with the given type. More... | |
template<typename T > | |
constexpr const T && | get () const &&requires(variant_has_alternative_v< T |
Access the underlying value with the given type. More... | |
template<std::size_t Index> | |
constexpr variant_alternative_t< Index, Variant > & | get () & |
Access the underlying value with the given index. More... | |
template<std::size_t Index> | |
constexpr const variant_alternative_t< Index, Variant > & | get () const & |
Access the underlying value with the given index. More... | |
template<std::size_t Index> | |
constexpr variant_alternative_t< Index, Variant > && | get () && |
Access the underlying value with the given index. More... | |
template<std::size_t Index> | |
constexpr const variant_alternative_t< Index, Variant > && | get () const && |
Access the underlying value with the given index. More... | |
template<typename T > | |
constexpr T * | get_if () noexcept requires(variant_has_alternative_v< T |
Access the underlying value with the given type if it is the currently active alternative. More... | |
template<typename T > | |
constexpr const T * | get_if () const noexcept requires(variant_has_alternative_v< T |
Access the underlying value with the given type if it is the currently active alternative. More... | |
template<std::size_t Index> | |
constexpr variant_alternative_t< Index, Variant > * | get_if () noexcept |
Access the underlying value with the given index if it is the currently active alternative. More... | |
template<std::size_t Index> | |
constexpr const variant_alternative_t< Index, Variant > * | get_if () const noexcept |
Access the underlying value with the given index if it is the currently active alternative. More... | |
Static Public Member Functions | |
template<typename Visitor , typename V > | |
static constexpr decltype(auto) | visit (Visitor &&visitor, V &&variant) |
Call a visitor functor with the currently active underlying value of a variant. More... | |
Public Attributes | |
constexpr Variant | Variant |
constexpr Variant | ilist |
constexpr bool | Variant |
constexpr T | Variant |
constexpr const T | Variant |
Static Public Attributes | |
static constexpr index_type | npos = sizeof...(Ts) |
Invalid alternative index, representing the valueless by exception state. More... | |
Friends | |
constexpr friend void | swap (Variant &a, Variant &b) noexcept(noexcept(a.swap(b))) |
Swap the values of two variants. More... | |
Tagged union value type that holds a value of one of the given types.
Its API mimics that of std::variant, with some added convenience functions such as Variant::is(), Variant::as() and match().
Ts | type alternatives that can be held by the variant. |
using donut::Variant< Ts >::index_type = std::conditional_t<sizeof...(Ts) < 255ull, std::uint8_t, std::conditional_t<sizeof...(Ts) < 65535ull, std::uint16_t, std::conditional_t<sizeof...(Ts) < 4294967295ull, std::uint32_t, std::uint64_t> >> |
Index type used to encode the active alternative type.
This is automatically sized to the smallest possible standard unsigned integer type that can represent all of the possible variant alternatives, including the valueless by exception state.
|
inlineconstexprnoexcept |
Default-construct a variant with the first variant alternative, if it is default-constructible.
any | exception thrown by the underlying constructor of the first alternative type. |
|
inlineconstexprnoexcept |
Converting constructor.
Chooses the variant alternative type to construct based on the overloading rules specified by std::variant.
value | underlying value to construct the variant from. Must be convertible to one of the variant's listed alternative types. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
explicitconstexpr |
Construct a variant alternative in-place given its type.
type | std::in_place_type<T>, where T is the alternative type to construct, which must be one of the variant's listed alternative types. |
args | arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
explicitconstexpr |
Construct a variant alternative in-place given its type, with an initializer list as the first constructor argument.
type | std::in_place_type<T>, where T is the alternative type to construct, which must be one of the variant's listed alternative types. |
ilist | first argument to pass to the underlying value's constructor. |
args | subsequent arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
inlineexplicitconstexpr |
Construct a variant alternative in-place given its index.
index | std::in_place_index<Index>, where Index is the alternative index to construct, which must be within the range of the variant's list of alternative types. |
args | arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
inlineexplicitconstexpr |
Construct a variant alternative in-place given its index, with an initializer list as the first constructor argument.
index | std::in_place_index<Index>, where Index is the alternative index to construct, which must be within the range of the variant's list of alternative types. |
ilist | first argument to pass to the underlying value's constructor. |
args | subsequent arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
inlineconstexpr |
Destructor.
|
constexprdefault |
Trivial destructor.
|
constexprdelete |
Deleted copy constructor.
|
constexprdefault |
Trivial copy constructor.
|
inlineconstexpr |
Copy constructor.
|
constexprdefaultnoexcept |
Trivial move constructor.
|
inlineconstexprnoexcept |
Move constructor.
|
inline |
|
inline |
|
constexprdelete |
Deleted copy assignment.
|
constexprdefault |
Trivial copy assignment.
|
inlineconstexpr |
Copy assignment.
|
constexprdefaultnoexcept |
Trivial move assignment.
|
inlineconstexprnoexcept |
Move assignment.
|
inlineconstexprnoexcept |
Converting assignment.
Chooses the variant alternative type to construct or assign based on the overloading rules specified by std::variant.
value | underlying value to construct the new value with. Must be convertible to one of the variant's listed alternative types. |
any | exception thrown by the underlying constructor or assignment of the relevant alternative type. |
|
constexpr |
Construct an alternative given its type, destroying the old value.
T | the alternative type to construct. Must be one of the variant's listed alternative types. |
args | arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
constexpr |
Construct an alternative given its type, with an initializer list as the first constructor argument, destroying the old value.
T | the alternative type to construct. Must be one of the variant's listed alternative types. |
ilist | first argument to pass to the underlying value's constructor. |
args | subsequent arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
inlineconstexpr |
Construct an alternative given its index, destroying the old value.
Index | the alternative index to construct. Must be within the range of the variant's list of alternative types. |
args | arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
inlineconstexpr |
Construct an alternative given its index, with an initializer list as the first constructor argument, destroying the old value.
Index | the alternative index to construct. Must be within the range of the variant's list of alternative types. |
ilist | first argument to pass to the underlying value's constructor. |
args | subsequent arguments to pass to the underlying value's constructor. |
any | exception thrown by the underlying constructor of the relevant alternative type. |
|
inlineconstexprnoexcept |
Swap this variant's value with that of another.
other | variant to swap with. |
any | exception thrown by the underlying constructor, assignment or swap implementation of the relevant alternative types. |
|
inlineconstexprnoexcept |
Get the alternative index of the currently active value held by the variant.
|
inlineconstexprnoexcept |
Check if the variant is in the valueless by exception state.
|
constexprnoexcept |
Check if the variant currently holds the alternative with the given type.
T | alternative type to check for. Must be one of the variant's listed alternative types. |
|
inlineconstexprnoexcept |
Check if the variant currently holds the alternative with the given index.
Index | alternative index to check for. Must be within the range of the variant's list of alternative types. |
|
constexprnoexcept |
Access the underlying value with the given type without a safety check.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
return donut::Variant< Ts >::as | ( | ) |
|
constexprnoexcept |
Access the underlying value with the given type without a safety check.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
return donut::Variant< Ts >::as | ( | ) |
|
constexprnoexcept |
Access the underlying value with the given type without a safety check.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
return donut::Variant< Ts >::std::move | ( | as< variant_index_v< T, Variant< Ts > >> | () | ) |
|
constexprnoexcept |
Access the underlying value with the given type without a safety check.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
return donut::Variant< Ts >::std::move | ( | as< variant_index_v< T, Variant< Ts > >> | () | ) |
|
inlineconstexprnoexcept |
Access the underlying value with the given index without a safety check.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
|
inlineconstexprnoexcept |
Access the underlying value with the given index without a safety check.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
|
inlineconstexprnoexcept |
Access the underlying value with the given index without a safety check.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
|
inlineconstexprnoexcept |
Access the underlying value with the given index without a safety check.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
|
constexpr |
Access the underlying value with the given type.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
BadVariantAccess | if the variant does not currently hold a value of the given type. |
|
constexpr |
Access the underlying value with the given type.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
BadVariantAccess | if the variant does not currently hold a value of the given type. |
|
constexpr |
Access the underlying value with the given type.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
BadVariantAccess | if the variant does not currently hold a value of the given type. |
|
constexpr |
Access the underlying value with the given type.
T | type of the currently active value to get. Must be one of the variant's listed alternative types. |
BadVariantAccess | if the variant does not currently hold a value of the given type. |
|
inlineconstexpr |
Access the underlying value with the given index.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
BadVariantAccess | if the variant does not currently hold the given alternative. |
|
inlineconstexpr |
Access the underlying value with the given index.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
BadVariantAccess | if the variant does not currently hold the given alternative. |
|
inlineconstexpr |
Access the underlying value with the given index.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
BadVariantAccess | if the variant does not currently hold the given alternative. |
|
inlineconstexpr |
Access the underlying value with the given index.
Index | alternative index of the currently active value to get. Must be within the range of the variant's list of alternative types. |
BadVariantAccess | if the variant does not currently hold the given alternative. |
|
constexprnoexcept |
Access the underlying value with the given type if it is the currently active alternative.
T | type of the value to get. Must be one of the variant's listed alternative types. |
|
constexprnoexcept |
Access the underlying value with the given type if it is the currently active alternative.
T | type of the value to get. Must be one of the variant's listed alternative types. |
|
inlineconstexprnoexcept |
Access the underlying value with the given index if it is the currently active alternative.
Index | alternative index of the value to get. Must be within the range of the variant's list of alternative types. |
|
inlineconstexprnoexcept |
Access the underlying value with the given index if it is the currently active alternative.
Index | alternative index of the value to get. Must be within the range of the variant's list of alternative types. |
|
inlinestaticconstexpr |
Call a visitor functor with the currently active underlying value of a variant.
visitor | callable object that is overloaded to accept any of the variant alternatives as a parameter. |
variant | variant whose underlying value to pass to the visitor. |
BadVariantAccess | if the variant is in the valueless by exception state. |
any | exception thrown by the visitor. |
Swap the values of two variants.
a | first variant. |
b | second variant. |
any | exception thrown by the underlying constructor, assignment or swap implementation of the relevant alternative types. |
|
staticconstexpr |
Invalid alternative index, representing the valueless by exception state.
constexpr const T donut::Variant< Ts >::Variant |
constexpr Variant donut::Variant< Ts >::ilist |
constexpr bool donut::Variant< Ts >::Variant |
constexpr T donut::Variant< Ts >::Variant |
constexpr const T donut::Variant< Ts >::Variant |