Skip to content
Snippets Groups Projects
Commit 02ffbc31 authored by Max Kahnt's avatar Max Kahnt
Browse files

Add trait utilities.

parent 407ab86d
No related branches found
No related tags found
No related merge requests found
#ifndef DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH
#define DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH
#include <type_traits>
#include <dune/common/std/type_traits.hh>
#include <dune/common/typetraits.hh>
#include <dune/matrix-vector/concepts.hh>
#include <dune/matrix-vector/scalartraits.hh>
#include <dune/matrix-vector/matrixtraits.hh>
#include <dune/matrix-vector/vectortraits.hh>
namespace Dune {
namespace MatrixVector {
// convenience compile-time functions to classify types
template <class T>
constexpr auto isNumber() {
return Std::bool_constant<IsNumber<T>::value>();
}
template <class T>
constexpr auto isScalar() {
return Std::bool_constant<ScalarTraits<T>::isScalar>();
}
template <class T>
constexpr auto isVector() {
return Std::bool_constant<VectorTraits<T>::isVector>();
}
template <class T>
constexpr auto isMatrix() {
return Std::bool_constant<MatrixTraits<T>::isMatrix>();
}
template <class T>
constexpr auto isTupleOrDerived() {
return Std::bool_constant<IsTupleOrDerived<std::decay_t<T>>::value>();
}
// enable_if typedefs for traits ...
template <class T>
using EnableNumber = std::enable_if_t<isNumber<T>()>;
template <class T>
using EnableScalar = std::enable_if_t<isScalar<T>()>;
template <class T>
using EnableVector = std::enable_if_t<isVector<T>()>;
template <class T>
using EnableMatrix = std::enable_if_t<isMatrix<T>()>;
// ... and their negations
template <class T>
using DisableNumber = std::enable_if_t<not isNumber<T>()>;
template <class T>
using DisableScalar = std::enable_if_t<not isScalar<T>()>;
template <class T>
using DisableVector = std::enable_if_t<not isVector<T>()>;
template <class T>
using DisableMatrix = std::enable_if_t<not isMatrix<T>()>;
// compile-time property checks
template <class T>
constexpr auto isSparseRangeIterable() {
return Std::bool_constant<isTupleOrDerived<T>() or
models<Concept::HasBegin, T>()>();
}
} // end namespace MatrixVector
} // end namespace Dune
#endif // DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment