File traits.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
aIf the matrix is singular (ill conditioned), the determinant is return. Otherwise, an empty
std::optionalis return-
namespace utils#
Typedefs
- template<class... Ts> EnableIfField = std::enable_if_t<(is_Field_v< Ts > and ...), std::common_type_t< Ts... > >
Enable a function if all the Ts are subclasses of
Field, and returns the common type: i.e.Field3Dif at least one argument isField3D, otherwiseField2Dif they are allField2DThis is most useful in two particular cases:
when there are multiple overloads for a function but some only make sense for fields (as opposed to
BoutReal, say) or vice-versa, and some overloads should not be used for fieldswhen a function takes multiple fields and the return type is also a field and must be “big enough”
In other cases, such as a function without overloads that only works for fields, consider using
static_assertwithis_Fieldto give a nice compile-time errorExamples
Consider the following template function:
This function only “appears” iftemplate <class T, class U, class V, class ResultType = typename bout::utils::EnableIfField<T, U, V>> auto where(const T& test, const U& gt0, const V& le0) -> ResultType { // function body }
T,UandVare all subclasses ofField.ResultTypeis the common type ofT,UandV. IfTandUare bothField2D,ResultTypeisField2DifVisField2D, andField3DifVisField3D.
- template<class... Ts> EnableIfField2D = std::enable_if_t<(is_Field2D_v< Ts > and ...), std::common_type_t< Ts... > >
Enable a function if all the Ts are subclasses of
Field2D, and returns the common type
- template<class... Ts> EnableIfField3D = std::enable_if_t<(is_Field3D_v< Ts > and ...), std::common_type_t< Ts... > >
Enable a function if all the Ts are subclasses of
Field3D, and returns the common type
- template<class... Ts> EnableIfFieldPerp = std::enable_if_t<(is_FieldPerp_v< Ts > and ...), std::common_type_t< Ts... > >
Enable a function if all the Ts are subclasses of
FieldPerp, and returns the common type
Variables
-
template<class T>
constexpr bool is_Field_v = std::is_base_of_v<Field, T># True if
Tis derived fromField, otherwise falseExamples
template <class T> void print_field(const T& field) { static_assert(bout::utils::is_Field_v<T>, "print_field only works with Field2Ds, Field3Ds or FieldPerps") // implementation }
-
template<class T>
constexpr bool is_Field2D_v = std::is_base_of_v<Field2D, T># True if
Tis derived fromField2D, otherwise false.
-
template<class T>
constexpr bool is_Field3D_v = std::is_base_of_v<Field3D, T># True if
Tis derived fromField3D, otherwise false.
-
namespace utils#