|
EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
|
VariantHelpers specification. More...
Go to the source code of this file.
Classes | |
| struct | echomap::variant_helpers::IsVariantAlternative< T, Variant > |
| Determines whether a type is one of the alternatives of a std::variant. More... | |
| struct | echomap::variant_helpers::IsVariantAlternative< T, std::variant< Alternatives... > > |
| Specialisation for std::variant types. More... | |
| struct | echomap::variant_helpers::Overloaded< Ts > |
| A helper type for succinctly specifying callable visitors over a variant alternative. More... | |
Namespaces | |
| namespace | echomap |
| The main EchoMap outermost namespace for all non-exported symbols. | |
Concepts | |
| concept | echomap::variant_helpers::VariantAlternative |
| Constrains a type to be one of the alternatives of a std::variant. | |
Functions | |
| template<class Variant, class NameGetter, std::size_t... indices> | |
| consteval auto | echomap::variant_helpers::make_variant_name_array (std::index_sequence< indices... > sequence) |
| Produces an array of human-readable names for selected alternatives of a variant. | |
| template<class Variant, std::size_t index> | |
| constexpr Variant | echomap::variant_helpers::make_variant_alternative () |
| Constructs a variant holding the alternative at a compile-time index. | |
| template<class Variant, std::size_t... indices> | |
| consteval auto | echomap::variant_helpers::make_variant_factory_array (std::index_sequence< indices... > sequence) |
| Produces an array of factory function pointers for constructing a variant by alternative index. | |
| template<class Variant> | |
| Variant | echomap::variant_helpers::variant_from_index (const std::size_t index) |
Constructs a std::variant holding the alternative at the given runtime index. | |
Variables | |
| template<typename T, typename Variant> | |
| constexpr bool | echomap::variant_helpers::is_variant_alternative_v |
| Whether a type is an alternative of a std::variant. | |
| template<class Variant, class NameGetter> | |
| constexpr auto | echomap::variant_helpers::variant_name_array |
| Array of human-readable names for every alternative in a variant. | |
|
constexpr |
Constructs a variant holding the alternative at a compile-time index.
The returned variant is constructed with std::in_place_index for Index. Therefore, the initially held alternative is the default-constructed Index-th alternative type of Variant.
For example, for std::variant<A, B, C>, calling this function with Index set to 1 returns a variant holding a default-constructed B.
| Variant | The variant type to construct. |
| index | The index of the alternative to hold initially. |
Variant holding a default-constructed instance of the alternative at Index.Variant must be a specialization of std::variant. Index must be a valid alternative index for Variant. Definition at line 181 of file VariantHelpers.hpp.
|
consteval |
Produces an array of factory function pointers for constructing a variant by alternative index.
Given a variant type std::variant<A, B, C> and an index sequence equivalent to std::index_sequence<0, 1, 2>, this function returns an array of type:
The function pointer at position \( i \) constructs a Variant whose initially held alternative is the default-constructed \( i \)-th alternative type.
For example, calling the factory at index 1 for std::variant<A, B, C> returns a variant holding a default-constructed B.
| Variant | The variant type constructed by the returned factory functions. |
| indices | The alternative indices for which factory functions are generated. |
| sequence | The index sequence identifying the variant alternatives. The value is used only for template argument deduction. |
Variant holding the default-constructed alternative corresponding to its index.Indices must be a valid alternative index for Variant. Definition at line 215 of file VariantHelpers.hpp.
|
consteval |
Produces an array of human-readable names for selected alternatives of a variant.
Given a variant type std::variant<A, B, C>, a name getter NameGetter, and an index sequence equivalent to std::index_sequence<0, 1, 2>, this function returns an array containing:
The returned array preserves the alternative ordering of Variant. Therefore, the name at position \( i \) corresponds to the \( i \)-th selected alternative index in the supplied index sequence.
| Variant | The variant type whose alternative names are generated. |
| NameGetter | A policy type providing NameGetter::template get<T>() for each selected alternative type. |
| indices | The alternative indices for which names are generated. |
| sequence | The index sequence identifying the variant alternatives. The value is used only for template argument deduction. |
Variant must be a specialization of std::variant. Indices must be a valid alternative index for Variant. NameGetter must provide a valid get<T>() function for every selected alternative type. Definition at line 127 of file VariantHelpers.hpp.
| Variant echomap::variant_helpers::variant_from_index | ( | const std::size_t | index | ) |
Constructs a std::variant holding the alternative at the given runtime index.
The returned variant is constructed with std::in_place_index for the requested alternative index. The selected alternative is default-constructed.
| Variant | The variant type to construct. |
| index | The index of the alternative that should be initially held by the variant. |
Variant holding a default-constructed instance of the alternative at index.| std::out_of_range | index is not a valid alternative index for Variant. |
Variant must be a specialization of std::variant. Definition at line 243 of file VariantHelpers.hpp.
|
inlineconstexpr |
Whether a type is an alternative of a std::variant.
Removes cv-qualifiers and references from both T and Variant before performing the test.
| T | The type to test. |
| Variant | The variant type whose alternatives should be inspected. |
Definition at line 54 of file VariantHelpers.hpp.
|
inlineconstexpr |
Array of human-readable names for every alternative in a variant.
The array order matches the alternative order of Variant. Therefore, index \( i \) in this array names the same alternative selected by std::variant::index() == i.
Names are obtained from NameGetter, which must provide a templated static function of the form:
| Variant | The variant type whose alternatives are named. |
| NameGetter | A policy type used to obtain names for each alternative type. |
Variant must be a specialization of std::variant. Variant must be accepted by NameGetter. Definition at line 157 of file VariantHelpers.hpp.