From ba5d73e42648507f8a815f573d38355076aef5f6 Mon Sep 17 00:00:00 2001 From: Kilian Date: Thu, 23 Apr 2020 18:38:56 +0200 Subject: [PATCH 1/3] [common] Add function rows(multiTypeBlockMatrix) --- dumux/common/typetraits/utility.hh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dumux/common/typetraits/utility.hh b/dumux/common/typetraits/utility.hh index 20d69bb102..92eff98765 100644 --- a/dumux/common/typetraits/utility.hh +++ b/dumux/common/typetraits/utility.hh @@ -27,6 +27,12 @@ #include #include +// Forward declare to avoid includes +namespace Dune { +template +class MultiTypeBlockMatrix; +} + namespace Dumux { /* @@ -53,6 +59,12 @@ namespace Detail { { using type = std::index_sequence; }; + + template + auto constexpr rowsImpl(Matrix& mat, std::index_sequence) + { + return RowType(std::get(mat)...); + } } /* @@ -98,6 +110,22 @@ constexpr auto makeIndexSequenceWithOffset() return addOffsetToIndexSequence(std::make_index_sequence{}); } +template +auto constexpr rows(const Dune::MultiTypeBlockMatrix& matrix) +{ + using Type = std::tuple; + using Indices = std::index_sequence_for; + return Detail::rowsImpl&, Type>(matrix, Indices{}); +} + +template +auto constexpr rows(Dune::MultiTypeBlockMatrix& matrix) +{ + using Type = std::tuple; + using Indices = std::index_sequence_for; + return Detail::rowsImpl&, Type>(matrix, Indices{}); +} + } // end namespace Dumux #endif -- GitLab From 93895fb0c6e9e7c18e3231bcd58f34283dea20e9 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Thu, 23 Apr 2020 19:54:44 +0200 Subject: [PATCH 2/3] fixup --- dumux/common/typetraits/utility.hh | 31 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/dumux/common/typetraits/utility.hh b/dumux/common/typetraits/utility.hh index 92eff98765..9fa819ab9b 100644 --- a/dumux/common/typetraits/utility.hh +++ b/dumux/common/typetraits/utility.hh @@ -26,6 +26,7 @@ #include #include +#include // Forward declare to avoid includes namespace Dune { @@ -60,11 +61,18 @@ namespace Detail { using type = std::index_sequence; }; - template - auto constexpr rowsImpl(Matrix& mat, std::index_sequence) + template + struct NumRows { - return RowType(std::get(mat)...); + static constexpr auto value = sizeof...(Args)+1; + }; + + template + auto constexpr forwardAsTuple(M&& m, std::index_sequence) + { + return std::forward_as_tuple(std::get(m)...); } + } /* @@ -110,20 +118,11 @@ constexpr auto makeIndexSequenceWithOffset() return addOffsetToIndexSequence(std::make_index_sequence{}); } -template -auto constexpr rows(const Dune::MultiTypeBlockMatrix& matrix) -{ - using Type = std::tuple; - using Indices = std::index_sequence_for; - return Detail::rowsImpl&, Type>(matrix, Indices{}); -} - -template -auto constexpr rows(Dune::MultiTypeBlockMatrix& matrix) +template +auto constexpr rows(M&& m) { - using Type = std::tuple; - using Indices = std::index_sequence_for; - return Detail::rowsImpl&, Type>(matrix, Indices{}); + return Detail::forwardAsTuple(std::forward(m), + std::make_index_sequence::value>{}); } } // end namespace Dumux -- GitLab From ac90f598589e47956aeba895f945c9a6962b8ec1 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Thu, 23 Apr 2020 20:00:44 +0200 Subject: [PATCH 3/3] fixup 2 --- dumux/common/typetraits/utility.hh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dumux/common/typetraits/utility.hh b/dumux/common/typetraits/utility.hh index 9fa819ab9b..c5e4e51b69 100644 --- a/dumux/common/typetraits/utility.hh +++ b/dumux/common/typetraits/utility.hh @@ -61,18 +61,11 @@ namespace Detail { using type = std::index_sequence; }; - template - struct NumRows - { - static constexpr auto value = sizeof...(Args)+1; - }; - template auto constexpr forwardAsTuple(M&& m, std::index_sequence) { return std::forward_as_tuple(std::get(m)...); } - } /* @@ -122,7 +115,7 @@ template auto constexpr rows(M&& m) { return Detail::forwardAsTuple(std::forward(m), - std::make_index_sequence::value>{}); + std::make_index_sequence::N()>{}); } } // end namespace Dumux -- GitLab