From 16eaf7a6dd0bfb4acc56c7fd99d158dd2094457b Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 9 Sep 2019 23:50:20 +0200 Subject: [PATCH 1/3] Added extended AllTrueBitSetVector class --- src/amdis/functions/Interpolate.hpp | 13 +++--- src/amdis/utility/AllTrueBitSetVector.hpp | 53 +++++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 src/amdis/utility/AllTrueBitSetVector.hpp diff --git a/src/amdis/functions/Interpolate.hpp b/src/amdis/functions/Interpolate.hpp index bdbea99e..cd5703da 100644 --- a/src/amdis/functions/Interpolate.hpp +++ b/src/amdis/functions/Interpolate.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace AMDiS { namespace Impl { @@ -284,7 +285,7 @@ template const& treePath, Vec& vec, C& count, GF const& gf, NTRE const& nodeToRangeEntry, bool_t) { - auto bitVec = Dune::Functions::Imp::AllTrueBitSetVector(); + auto bitVec = AllTrueBitSetVector{}; AMDiS::interpolateTreeSubset(basis, treePath, vec, count, bitVec, gf, nodeToRangeEntry, bool_t{}); } @@ -295,7 +296,7 @@ template const& treePath, Vec& vec, C& count, GF const& gf, bool_t) { - auto bitVec = Dune::Functions::Imp::AllTrueBitSetVector(); + auto bitVec = AllTrueBitSetVector{}; auto ntrm = AMDiS::HierarchicNodeToRangeMap(); AMDiS::interpolateTreeSubset(basis, treePath, vec, count, bitVec, gf, ntrm, bool_t{}); } @@ -380,7 +381,7 @@ template ) { auto root = Dune::TypeTree::hybridTreePath(); - auto bitVec = Dune::Functions::Imp::AllTrueBitSetVector(); + auto bitVec = AllTrueBitSetVector{}; AMDiS::interpolateFiltered(basis, root, vec, count, bitVec, gf, bool_t{}); } @@ -391,7 +392,7 @@ template const& treePath, Vec& vec, C& count, GF const& gf, bool_t) { - auto bitVec = Dune::Functions::Imp::AllTrueBitSetVector(); + auto bitVec = AllTrueBitSetVector{}; AMDiS::interpolateFiltered(basis, treePath, vec, count, bitVec, gf, bool_t{}); } @@ -428,7 +429,7 @@ template )> void interpolate(B const& basis, Dune::TypeTree::HybridTreePath const& treePath, Vec& vec, GF const& gf) { - auto bitVec = Dune::Functions::Imp::AllTrueBitSetVector(); + auto bitVec = AllTrueBitSetVector{}; auto count = Impl::FakeCounter(); AMDiS::interpolateFiltered(basis, treePath, vec, count, bitVec, gf, std::false_type{}); } diff --git a/src/amdis/utility/AllTrueBitSetVector.hpp b/src/amdis/utility/AllTrueBitSetVector.hpp new file mode 100644 index 00000000..70267bce --- /dev/null +++ b/src/amdis/utility/AllTrueBitSetVector.hpp @@ -0,0 +1,53 @@ +#pragma once + +namespace AMDiS +{ + /// \brief Vector-like container of bools returning always true + class AllTrueBitSetVector + { + struct const_iterator + { + constexpr const_iterator(bool sentinel = false) noexcept : sentinel_(sentinel) {} + constexpr bool operator*() const noexcept { return true; } + constexpr const_iterator& operator++() noexcept { return *this; } + constexpr const_iterator operator++(int) noexcept { return *this; } + + /// Comparison of the iterator is always true if both are sentinel or both are const_iterator + friend constexpr bool operator==(const_iterator a, const_iterator b) noexcept + { + return a.sentinel_ == b.sentinel_; + } + + bool sentinel_ = false; + }; + + /// Constexpr default constructor + constexpr AllTrueBitSetVector() noexcept = default; + + /// Converting to true + constexpr operator bool() const noexcept + { + return true; + } + + /// Access any element of the container returning always true. + template + constexpr const AllTrueBitSetVector& operator[](Index const& /*index*/) const noexcept + { + return *this; + } + + /// Return iterator that always redirects to a bool true. + constexpr const_iterator begin() const noexcept { return const_iterator{false}; } + constexpr const_iterator end() const noexcept { return const_iterator{true}; } + + /// Return iterator that always redirects to a bool true. + constexpr const_iterator cbegin() const noexcept { return const_iterator{false}; } + constexpr const_iterator cend() const noexcept { return const_iterator{true}; } + + /// Resize does nothing + template + constexpr void resize(Size const& /*size*/) const noexcept { /* do nothing */ } + }; + +} // end namespace AMDiS -- GitLab From d4b9a66f3d097a708397d0ef73e8a478b160b185 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Tue, 10 Sep 2019 00:42:41 +0200 Subject: [PATCH 2/3] make AllTrueBitSetVector public --- src/amdis/utility/AllTrueBitSetVector.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/amdis/utility/AllTrueBitSetVector.hpp b/src/amdis/utility/AllTrueBitSetVector.hpp index 70267bce..dc714924 100644 --- a/src/amdis/utility/AllTrueBitSetVector.hpp +++ b/src/amdis/utility/AllTrueBitSetVector.hpp @@ -5,6 +5,7 @@ namespace AMDiS /// \brief Vector-like container of bools returning always true class AllTrueBitSetVector { + public: struct const_iterator { constexpr const_iterator(bool sentinel = false) noexcept : sentinel_(sentinel) {} -- GitLab From aa3171870a7f94ee1cfb48bf271d5257c0cd14f5 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 23 Sep 2019 12:48:33 +0200 Subject: [PATCH 3/3] make AllTrueBitSetVector an infinite range --- src/amdis/utility/AllTrueBitSetVector.hpp | 70 +++++++++++++++++------ test/AllTrueBitSetVectorTest.cpp | 36 ++++++++++++ test/CMakeLists.txt | 3 + 3 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 test/AllTrueBitSetVectorTest.cpp diff --git a/src/amdis/utility/AllTrueBitSetVector.hpp b/src/amdis/utility/AllTrueBitSetVector.hpp index dc714924..54c2d7c6 100644 --- a/src/amdis/utility/AllTrueBitSetVector.hpp +++ b/src/amdis/utility/AllTrueBitSetVector.hpp @@ -1,54 +1,92 @@ #pragma once +#include +#include + namespace AMDiS { - /// \brief Vector-like container of bools returning always true + /// \brief Vector-like container of bools returning always true. + /** + * Model of an infinite range of bools of value `true` with vector-like element + * access by `operator[]`. + **/ class AllTrueBitSetVector { public: + using value_type = bool; + struct const_iterator { - constexpr const_iterator(bool sentinel = false) noexcept : sentinel_(sentinel) {} + using value_type = bool; + using reference = bool; + using difference_type = std::ptrdiff_t; + using iterator_category = std::forward_iterator_tag; + constexpr bool operator*() const noexcept { return true; } constexpr const_iterator& operator++() noexcept { return *this; } constexpr const_iterator operator++(int) noexcept { return *this; } - /// Comparison of the iterator is always true if both are sentinel or both are const_iterator - friend constexpr bool operator==(const_iterator a, const_iterator b) noexcept - { - return a.sentinel_ == b.sentinel_; - } - - bool sentinel_ = false; + /// Comparison of the iterator is always true + constexpr bool operator==(const_iterator) const noexcept { return true; } + constexpr bool operator!=(const_iterator) const noexcept { return false; } }; /// Constexpr default constructor constexpr AllTrueBitSetVector() noexcept = default; + + public: // element access + /// Converting to true constexpr operator bool() const noexcept { return true; } - /// Access any element of the container returning always true. + /// Access to any element of the container returns always true. template - constexpr const AllTrueBitSetVector& operator[](Index const& /*index*/) const noexcept + constexpr AllTrueBitSetVector const& at(Index const& /*index*/) const noexcept + { + return *this; + } + + /// Access to any element of the container returns always true. + template + constexpr AllTrueBitSetVector const& operator[](Index const& /*index*/) const noexcept + { + return *this; + } + + /// Access the front element of the infinite range + constexpr AllTrueBitSetVector const& front() const noexcept { return *this; } + + public: // iterators + /// Return iterator that always redirects to a bool true. - constexpr const_iterator begin() const noexcept { return const_iterator{false}; } - constexpr const_iterator end() const noexcept { return const_iterator{true}; } + constexpr const_iterator begin() const noexcept { return const_iterator{}; } /// Return iterator that always redirects to a bool true. - constexpr const_iterator cbegin() const noexcept { return const_iterator{false}; } - constexpr const_iterator cend() const noexcept { return const_iterator{true}; } + constexpr const_iterator cbegin() const noexcept { return const_iterator{}; } + + + public: // capacity and modifier /// Resize does nothing template - constexpr void resize(Size const& /*size*/) const noexcept { /* do nothing */ } + constexpr void resize(Size const& /*size*/) const noexcept + { + /* do nothing */ + } + + /// The container is always non-empty + constexpr bool empty() const noexcept + { + return false; + } }; } // end namespace AMDiS diff --git a/test/AllTrueBitSetVectorTest.cpp b/test/AllTrueBitSetVectorTest.cpp new file mode 100644 index 00000000..b112abcb --- /dev/null +++ b/test/AllTrueBitSetVectorTest.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include "Tests.hpp" + +using namespace AMDiS; + +int main(int argc, char** argv) +{ + constexpr auto bitSet = AllTrueBitSetVector{}; + + // The bitset is not empty + AMDIS_TEST(!bitSet.empty()); + + // All entries are true + std::size_t i = 0; + for (auto it = bitSet.begin(); i < 10; ++it, ++i) + AMDIS_TEST(*it); + + for (i = 0; i < 10; ++i) { + AMDIS_TEST(bitSet[i]); + AMDIS_TEST(bitSet.at(i)); + } + + // The front entry is true + AMDIS_TEST(bitSet.front()); + + // resize has not effect + bitSet.resize(0); + AMDIS_TEST(!bitSet.empty()); + + // use bitset element as template parameter + auto iconst = std::integral_constant{}; + + return report_errors(); +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d5e76ab8..7e7de14f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,6 +5,9 @@ dune_add_test(SOURCES AccessTest.cpp dune_add_test(SOURCES AdaptInfoTest.cpp LINK_LIBRARIES amdis) +dune_add_test(SOURCES AllTrueBitSetVectorTest.cpp + LINK_LIBRARIES amdis) + foreach(_GRID RANGE 7) dune_add_test(NAME "BackupRestoreTest_${_GRID}" SOURCES BackupRestoreTest.cpp -- GitLab