File 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

Provides access to the Hypre library, handling initialisation and finalisation.


#include <bout/hyprelib.hxx>

class MyClass { public:

private: HypreLib lib; };

This will then automatically initialise Hypre the first time an object is created, and finalise it when the last object is destroyed.

Copyright 2012 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu

Contact: Ben Dudson,

This file is part of BOUT++.

BOUT++ is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BOUT++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with BOUT++. If not, see

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

SNB model

namespace utils


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>...>#
#include <variant.hxx>

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

namespace details#
template<typename T, typename U>
struct CompareTypes#
#include <variant.hxx>

Compare two values. Different types -> false

Public Functions

inline 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

inline 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

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

Public Members

const T &t#
struct disjunction : public std::false_type#
#include <variant.hxx>

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#
#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>
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)#