File variant.hxx#

Variant utilities

All in namespace bout::utils

  • variant

  • visit

  • holds_alternative

  • get

  • variantEqualTo

  • variantStaticCastOrThrow

  • variantToString

Internal implementation in bout::utils::details

Defines

__VARIANT_HXX__#
namespace bout

Information about the version of BOUT++

The build system will update this file on every commit, which may result in files that include it getting rebuilt. Therefore it should be included in as few places as possible

Information about the version of BOUT++

The build system will update this file at configure-time

Explicit inversion of a 3x3 matrix a

If the matrix is singular (ill conditioned), the determinant is return. Otherwise, an empty std::optional is return

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 v 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 v cannot hold in which case std::bad_cast will be thrown at runtime

template<typename Variant>
std::string variantToString(const Variant &v)#
template<typename T, typename ...ALL_T>
struct isVariantMember<T, variant<ALL_T...>> : public bout::utils::details::disjunction<std::is_same<T, ALL_T>...>#

Is type T a member of variant variant<ALL_T>?

namespace details#
template<typename T, typename U>
struct CompareTypes#

Compare two values. Different types -> false

Public Functions

inline bool operator()(const T &v, const U &t)#
template<typename T>
struct CompareTypes<T, T>#

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

Public Functions

inline bool operator()(const T &v, const T &t)#
template<typename T>
struct IsEqual#

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

Public Functions

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

Public Members

const T &t#
template<class...>
struct disjunction : public std::false_type#

Backport of std::disjunction.

template<class B1>
struct disjunction<B1> : public B1#
template<class B1, class ...Bn>
struct disjunction<B1, Bn...> : public std::conditional_t<bool(B1::value), B1, disjunction<Bn...>>#
template<typename Target>
struct StaticCastOrThrow#

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>
inline Target operator()(Source &&source) const#
template<typename Source>
inline Target operator()(Source &&source, std::false_type)#
template<typename Source>
inline Target operator()(Source &&source, std::true_type)#
struct ToString#

Public Functions

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