diff --git a/src/amdis/functions/Interpolate.hpp b/src/amdis/functions/Interpolate.hpp index bdbea99e4c69fd07aa1ac5d0bb27111088b41c7c..cd5703da331c4501dc4a2ae08ba8823b34edfc93 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 0000000000000000000000000000000000000000..54c2d7c658c7e867b852d1a07667f99f1369b998 --- /dev/null +++ b/src/amdis/utility/AllTrueBitSetVector.hpp @@ -0,0 +1,92 @@ +#pragma once + +#include +#include + +namespace AMDiS +{ + /// \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 + { + 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 + 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 to any element of the container returns always true. + template + 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{}; } + + /// Return iterator that always redirects to a bool 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 */ + } + + /// 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 0000000000000000000000000000000000000000..b112abcbd44d3cc3195cdad8ef0d817c8a58ba4d --- /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 d5e76ab8a21f7749884497b33bdc2f019413db72..7e7de14fbbfd00a80a5a2ee1e5196989dfef3b59 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