File variant.hxx

Defines

__VARIANT_HXX__

Variant utilities

All in namespace bout::utils variant visit holds_alternative get

variantEqualTo variantStaticCastOrThrow variantToString

Internal implementation in bout::utils::details

namespace bout

SNB model

namespace utils

Functions

template<typename Variant, typename T>
bool variantEqualTo(const Variant &v, const T &t)

Return true only if the given variant v has the same type and value as t

Note: Handles the case that t is not of a type which can hold.

template<typename Variant, typename T>
T variantStaticCastOrThrow(const Variant &v)

Cast a variant to a given type using static_cast If this can’t be done then a std::bad_cast exception is thrown

Note: T can be a type which variant cannot hold in which case std::bad_cast will be thrown at runtime

template<typename Variant>
std::string variantToString(const Variant &v)
namespace details
template<typename T, typename U>
struct CompareTypes
#include <variant.hxx>

Compare two values. Different types -> false

Public Functions

bool operator()(const T &v, const U &t)
template<typename T>
struct CompareTypes<T, T>
#include <variant.hxx>

Compare two values Same type -> use == operator to compare

Public Functions

bool operator()(const T &v, const T &t)
template<typename T>
struct IsEqual
#include <variant.hxx>

A visitor for std::variant which compares the value stored in the variant with a given value using CompareTypes

Public Functions

IsEqual(const T &t)
template<typename U>
bool operator()(const U &u)

Public Members

const T &t
template<typename Target>
struct StaticCastOrThrow
#include <variant.hxx>

Functor to perform static casting with std::visit If the Target cannot be constructed from the Source then an exception (std::bad_cast) will be thrown at run time.

Note: This needs to be at runtime because the particular type which a variant is holding is only known at runtime.

Public Functions

template<typename Source>
Target operator()(Source &&source) const
template<typename Source>
Target operator()(Source &&source, std::false_type)
template<typename Source>
Target operator()(Source &&source, std::true_type)
struct ToString

Public Functions

template<typename T>
std::string operator()(T &&val)