![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/Utils/Variant.h>
Specialization of std::variant offering additional convenience member functions for functionality that the standard library only provides in the form of free functions. More...
Inheritance diagram for Variant< Types >:Specialization of std::variant offering additional convenience member functions for functionality that the standard library only provides in the form of free functions.
Due to design decisions of the C++ committee interaction with a std::variant requires extensive usage of free functions such as std::get_if<T>() or std::holds_alternative<T>(), which may be disliked for stylistic reasons by some people and also be more difficult to find for people unfamiliar with the interface.
Example:
Obviously, Utils::Variant behaves exactly like the underlying std::variant and you can still apply the standard library's free functions directly on it.
Public Member Functions | |
| Variant (const std::variant< Types... > &rhs) | |
| template<typename T> | |
| constexpr bool | holds () const noexcept |
Checks if the variant holds a value of type T. | |
| template<typename T> | |
| constexpr bool | equals (const T &value) const noexcept |
Checks if the variant holds a value of type T that equals value. | |
| template<typename T> | |
| constexpr T * | getIf () noexcept |
Attempts to retrieve the held value of type T as pointer or returns nullptr otherwise. | |
| template<typename T> | |
| constexpr const T * | getIf () const noexcept |
Attempts to retrieve the held value of type T as pointer or returns nullptr otherwise. | |
| template<class Visitor> | |
| constexpr auto | visit (Visitor &&visitor) |
| Applies the set of functions in visitor to this variant, picking the overload matching the current alternative. | |
| template<class Visitor> | |
| constexpr auto | visit (Visitor &&visitor) const |
| Applies the set of functions in visitor to this variant, picking the overload matching the current alternative. | |
Public Member Functions inherited from variant< Types... > | |
| T | emplace (T... args) |
| T | index (T... args) |
| T | operator= (T... args) |
| T | swap (T... args) |
| T | valueless_by_exception (T... args) |
| T | variant (T... args) |
| T | ~variant (T... args) |
|
inlineconstexprnoexcept |
Checks if the variant holds a value of type T.
T must appear exactly once in Types.
|
inlineconstexprnoexcept |
Checks if the variant holds a value of type T that equals value.
This is a convenience function for v.holds<T>() && *v.getIf<T>() == value. T must appear exactly once in Types.
|
inlineconstexprnoexcept |
Attempts to retrieve the held value of type T as pointer or returns nullptr otherwise.
T must appear exactly once in Types.
|
inlineconstexprnoexcept |
Attempts to retrieve the held value of type T as pointer or returns nullptr otherwise.
T must appear exactly once in Types.
|
inlineconstexpr |
Applies the set of functions in visitor to this variant, picking the overload matching the current alternative.
The visitor must accept every possible Type in Types. Example:
|
inlineconstexpr |
Applies the set of functions in visitor to this variant, picking the overload matching the current alternative.
The visitor must accept every possible Type in Types. Example: