diff --git a/dumux/common/typetraits/typetraits.hh b/dumux/common/typetraits/typetraits.hh index 3f1906478a0828de2fcfc7123ad9a53b4a4be120..d4359a7e92acd593ecd9a843db9fff3ead326d76 100644 --- a/dumux/common/typetraits/typetraits.hh +++ b/dumux/common/typetraits/typetraits.hh @@ -26,6 +26,8 @@ #include <type_traits> +#include <dune/common/version.hh> + namespace Dumux { /*! @@ -34,5 +36,17 @@ namespace Dumux */ template<typename T> struct AlwaysFalse : public std::false_type {}; + + /*! \brief We define our own is_indexable type in order + * to avoid several version checks throughout dumux. + * This should be deleted when the deprecation phase is over. + */ + template<typename T, typename I = std::size_t> + using IsIndexable = + #if DUNE_VERSION_NEWER(DUNE_COMMON,2,7) + typename Dune::IsIndexable<T, I>; + #else + typename Dune::is_indexable<T, I>; + #endif } #endif diff --git a/dumux/io/vtkfunction.hh b/dumux/io/vtkfunction.hh index 1a8ed80d81b5b45b7fe043d74e7a3cb2aebada6b..9a0667ac7278fbb7a4f701cfd5f5548c059d2bdd 100644 --- a/dumux/io/vtkfunction.hh +++ b/dumux/io/vtkfunction.hh @@ -30,6 +30,8 @@ #include <dune/grid/io/file/vtk/common.hh> #include <dune/grid/io/file/vtk/function.hh> +#include <dumux/common/typetraits/typetraits.hh> + namespace Dumux { namespace Vtk { @@ -56,7 +58,7 @@ public: //! evaluate virtual double evaluate(int mycomp, const Element& e, const Dune::FieldVector<ctype, dim>&) const - { return accessChooser_(mycomp, mapper_.index(e), Dune::is_indexable<decltype(field_[0])>()); } + { return accessChooser_(mycomp, mapper_.index(e), IsIndexable<decltype(field_[0])>()); } //! Constructor VectorP0VTKFunction(const GridView& gridView, const Mapper& mapper, const F& field, const std::string& name, int nComps) @@ -70,20 +72,16 @@ private: //! access for vectorial fields double accessChooser_(int mycomp, int i, std::true_type) const - { - static constexpr auto isIndexable = Dune::is_indexable<decltype(field_[0][0])>(); - return vectorFieldAccess_<isIndexable>(mycomp, i); } + { return vectorFieldAccess_(mycomp, i, IsIndexable<decltype(field_[0][0])>()); } //! access for scalar fields double accessChooser_(int mycomp, int i, std::false_type) const { return field_[i]; } //! access to permissive vectorial fields - template<bool is, std::enable_if_t<!is, int> = 0> - double vectorFieldAccess_(int mycomp, int i) const { return field_[i][mycomp]; } + double vectorFieldAccess_(int mycomp, int i, std::false_type) const { return field_[i][mycomp]; } //! if the field is indexable more than two times, throw error - template<bool is, std::enable_if_t<is, int> = 0> - double vectorFieldAccess_(int mycomp, int i) const { DUNE_THROW(Dune::InvalidStateException, "Invalid field type"); } + double vectorFieldAccess_(int mycomp, int i, std::true_type) const { DUNE_THROW(Dune::InvalidStateException, "Invalid field type"); } const F& field_; const std::string name_; @@ -120,7 +118,7 @@ public: std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices); for (unsigned i = 0; i < nVertices; ++i) - cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i, dim), Dune::is_indexable<decltype(field_[0])>()); + cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i, dim), IsIndexable<decltype(field_[0])>()); // (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues)); @@ -138,7 +136,7 @@ private: //! access for vectorial fields double accessChooser_(int mycomp, int i, std::true_type) const - { return vectorFieldAccess_(mycomp, i, Dune::is_indexable<decltype(field_[0][0])>()); } + { return vectorFieldAccess_(mycomp, i, IsIndexable<decltype(field_[0][0])>()); } //! access for scalar fields double accessChooser_(int mycomp, int i, std::false_type) const { return field_[i]; } @@ -184,7 +182,7 @@ public: std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices); for (unsigned i = 0; i < nVertices; ++i) - cornerValues[i] = accessChooser_(mycomp, mapper_.index(e), i, Dune::is_indexable<decltype(field_[0])>()); + cornerValues[i] = accessChooser_(mycomp, mapper_.index(e), i, IsIndexable<decltype(field_[0])>()); // (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues)); @@ -202,7 +200,7 @@ private: //! access to the field double accessChooser_(int mycomp, int eIdx, int cornerIdx, std::true_type) const - { return fieldAccess_(mycomp, eIdx, cornerIdx, Dune::is_indexable<decltype(field_[0][0])>()); } + { return fieldAccess_(mycomp, eIdx, cornerIdx, IsIndexable<decltype(field_[0][0])>()); } //! fields have to be indexable at least twice double accessChooser_(int mycomp, int eIdx, int cornerIdx, std::false_type) const diff --git a/dumux/io/vtkoutputmodule.hh b/dumux/io/vtkoutputmodule.hh index 65f045d5adca4856bf75c0ffafbcd1fc33bd38c0..366479b2ba74d45d0e7cfb42a9604b132d405723 100644 --- a/dumux/io/vtkoutputmodule.hh +++ b/dumux/io/vtkoutputmodule.hh @@ -42,6 +42,7 @@ #include <dumux/common/properties.hh> #include <dumux/common/parameters.hh> +#include <dumux/common/typetraits/typetraits.hh> #include <dumux/discretization/methods.hh> #include "vtkfunction.hh" @@ -569,11 +570,11 @@ private: } //! Deduces the number of components of the value type of a vector of values - template<class Vector, typename std::enable_if_t<Dune::is_indexable<decltype(std::declval<Vector>()[0])>::value, int> = 0> + template<class Vector, typename std::enable_if_t<IsIndexable<decltype(std::declval<Vector>()[0])>::value, int> = 0> std::size_t getNumberOfComponents_(const Vector& v) { return v[0].size(); } //! Deduces the number of components of the value type of a vector of values - template<class Vector, typename std::enable_if_t<!Dune::is_indexable<decltype(std::declval<Vector>()[0])>::value, int> = 0> + template<class Vector, typename std::enable_if_t<!IsIndexable<decltype(std::declval<Vector>()[0])>::value, int> = 0> std::size_t getNumberOfComponents_(const Vector& v) { return 1; } //! return the number of dofs