GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Variant.hpp File Reference

Go to the source code of this file.

Classes

struct  grem::Monostate
 Unit type for representing an empty alternative in Variant. More...
struct  std::hash< grem::Monostate >
struct  grem::BadVariantAccess
 Exception type that is thrown on an attempt to erroneously access an inactive alternative of a Variant when using a safe access function such as Variant::get(). More...
class  grem::Variant< Ts >
 Tagged union value type that holds a value of one of the given types. More...
struct  grem::Overloaded< Functors >
 Visitor type for combining callable objects, such as lambdas, into an overload set. More...
struct  std::hash< grem::Variant< Ts... > >

Namespaces

namespace  grem

Macros

#define GREM_MATCH(...)
#define GREM_CASE(...)
#define GREM_CASE_DEFAULT(...)

Typedefs

template<std::size_t Index, typename V>
using grem::variant_alternative_t = typename variant_alternative<Index, V>::type
 Get the type of the variant alternative with a given index in a variant type.

Functions

constexpr bool grem::operator== (Monostate, Monostate) noexcept
 Compare two monostates for equality.
constexpr std::strong_ordering grem::operator<=> (Monostate, Monostate) noexcept
 Compare two monostates.
template<typename Visitor, typename V>
requires (requires { typename std::remove_reference_t<V>::GREM_private_DerivedFromVariantTag; })
constexpr decltype(auto) grem::visit (Visitor &&visitor, V &&variant)
 Call a visitor functor with the currently active underlying value of a variant.
template<typename T, typename... Ts>
constexpr bool grem::holds_alternative (const Variant< Ts... > &variant) noexcept
 Check if a variant currently holds the alternative with the given type.
template<std::size_t Index, typename... Ts>
constexpr bool grem::holds_alternative (const Variant< Ts... > &variant) noexcept
 Check if a variant currently holds the alternative with the given index.
template<typename T, typename... Ts>
constexpr T & grem::get (Variant< Ts... > &variant)
 Access the underlying value with the given type of a variant.
template<typename T, typename... Ts>
constexpr const T & grem::get (const Variant< Ts... > &variant)
 Access the underlying value with the given type of a variant.
template<std::size_t Index, typename... Ts>
constexpr auto & grem::get (Variant< Ts... > &variant)
 Access the underlying value with the given index of a variant.
template<std::size_t Index, typename... Ts>
constexpr const auto & grem::get (const Variant< Ts... > &variant)
 Access the underlying value with the given index of a variant.
template<typename T, typename... Ts>
constexpr T * grem::get_if (Variant< Ts... > *variant) noexcept
 Access the underlying value with the given type of a variant if it is the currently active alternative.
template<typename T, typename... Ts>
constexpr const T * grem::get_if (const Variant< Ts... > *variant) noexcept
 Access the underlying value with the given type of a variant if it is the currently active alternative.
template<std::size_t Index, typename... Ts>
constexpr auto * grem::get_if (Variant< Ts... > *variant) noexcept
 Access the underlying value with the given index of a variant if it is the currently active alternative.
template<std::size_t Index, typename... Ts>
constexpr const auto * grem::get_if (const Variant< Ts... > *variant) noexcept
 Access the underlying value with the given index of a variant if it is the currently active alternative.
template<typename... Ts>
requires (requires { { a.template as<Ts>() == b.template as<Ts>() } -> detail::bool_convertible; } && ...)
constexpr bool grem::operator== (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Compare two variants for equality.
template<typename... Ts>
requires (requires { { a.template as<Ts>() != b.template as<Ts>() } -> detail::bool_convertible; } && ...)
constexpr bool grem::operator!= (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Compare two variants for inequality.
template<typename... Ts>
requires (requires { { a.template as<Ts>() < b.template as<Ts>() } -> detail::bool_convertible; } && ...)
constexpr bool grem::operator< (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Check if a variant is less than another variant.
template<typename... Ts>
requires (requires { { a.template as<Ts>() <= b.template as<Ts>() } -> detail::bool_convertible; } && ...)
constexpr bool grem::operator<= (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Check if a variant is less than or equal to another variant.
template<typename... Ts>
requires (requires { { a.template as<Ts>() > b.template as<Ts>() } -> detail::bool_convertible; } && ...)
constexpr bool grem::operator> (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Check if a variant is greater than another variant.
template<typename... Ts>
requires (requires { { a.template as<Ts>() >= b.template as<Ts>() } -> detail::bool_convertible; } && ...)
constexpr bool grem::operator>= (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Check if a variant is greater than or equal to another variant.
template<typename... Ts>
constexpr std::common_comparison_category_t< std::compare_three_way_result_t< Ts >... > grem::operator<=> (const Variant< Ts... > &a, const Variant< Ts... > &b)
 Compare two variants.
template<typename... Functors>
 grem::Overloaded (Functors...) -> Overloaded< Functors... >
template<typename V>
constexpr detail::Matcher< V > grem::match (V &&variant)
 Choose a function overload to execute based on the active alternative of a variant.

Variables

template<typename T, typename V>
constexpr bool grem::variant_has_alternative_v = variant_has_alternative<T, V>::value
 Check if a variant type has a given type as one of its possible alternatives.
template<typename T, typename V>
constexpr std::size_t grem::variant_index_v = variant_index<T, V>::value
 Get the index of the variant alternative with a given type in a variant type.
template<typename V>
constexpr std::size_t grem::variant_size_v = variant_size<V>::value
 Get the number of alternative types of a variant type.

Macro Definition Documentation

◆ GREM_MATCH

#define GREM_MATCH ( ...)
Value:
switch (auto&& GREM_private_matchVariant = __VA_ARGS__; GREM_private_matchVariant.index())

◆ GREM_CASE

#define GREM_CASE ( ...)
Value:
case grem::variant_index_v<grem::detail::match_case_type_t<void(__VA_ARGS__)>, decltype(grem::detail::matchVariantType(GREM_private_matchVariant))>: \
if ([[maybe_unused]] __VA_ARGS__ = GREM_private_matchVariant.template as<grem::detail::match_case_type_t<void(__VA_ARGS__)>>(); true)
Definition aliases.hpp:9
constexpr std::size_t variant_index_v
Get the index of the variant alternative with a given type in a variant type.
Definition Variant.hpp:196

◆ GREM_CASE_DEFAULT

#define GREM_CASE_DEFAULT ( ...)
Value:
default: \
if ([[maybe_unused]] __VA_ARGS__ = GREM_private_matchVariant; true)