diff --git a/src/mesh/SubItemArrayPerItem.hpp b/src/mesh/SubItemArrayPerItem.hpp index d39bff6a3015b61fbbe853dbeb9970e237068068..501762ea6270b7ebf59b26c4afdea6edd552cc3e 100644 --- a/src/mesh/SubItemArrayPerItem.hpp +++ b/src/mesh/SubItemArrayPerItem.hpp @@ -10,8 +10,6 @@ #include <utils/PugsAssert.hpp> #include <utils/Table.hpp> -#include <utils/SubArray.hpp> - #include <memory> template <typename DataType, typename ItemOfItem, typename ConnectivityPtr = std::shared_ptr<const IConnectivity>> diff --git a/src/utils/SubArray.hpp b/src/utils/SubArray.hpp deleted file mode 100644 index a5019dec9521039e420aeeef48c0439930a7840c..0000000000000000000000000000000000000000 --- a/src/utils/SubArray.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef SUB_ARRAY_HPP -#define SUB_ARRAY_HPP - -#include <utils/Array.hpp> -#include <utils/PugsAssert.hpp> -#include <utils/PugsMacros.hpp> -#include <utils/PugsUtils.hpp> - -#include <algorithm> - -template <typename DataType> -class [[nodiscard]] SubArray -{ - public: - using data_type = DataType; - using index_type = size_t; - - private: - PUGS_RESTRICT DataType* const m_sub_values; - const size_t m_size; - - // Allows const version to access our data - friend SubArray<std::add_const_t<DataType>>; - - public: - PUGS_INLINE size_t size() const noexcept - { - return m_size; - } - - PUGS_INLINE DataType& operator[](index_type i) const noexcept(NO_ASSERT) - { - Assert(i < m_size); - return m_sub_values[i]; - } - - PUGS_INLINE - void fill(const DataType& data) const - { - static_assert(not std::is_const<DataType>(), "Cannot modify SubArray of const"); - - // could consider to use std::fill - parallel_for( - this->size(), PUGS_LAMBDA(index_type i) { m_sub_values[i] = data; }); - } - - PUGS_INLINE - SubArray& operator=(const SubArray&) = delete; - - PUGS_INLINE - SubArray& operator=(SubArray&&) = delete; - - PUGS_INLINE - explicit SubArray(const Array<DataType>& array, size_t begin, size_t size) - : m_sub_values{&array[0] + begin}, m_size{size} - { - Assert(begin + size <= array.size(), "SubView is not contained in the source Array"); - } - - PUGS_INLINE - explicit SubArray(DataType* const raw_array, size_t begin, size_t size) - : m_sub_values{raw_array + begin}, m_size{size} - {} - - PUGS_INLINE - SubArray() = delete; - - PUGS_INLINE - SubArray(const SubArray&) = delete; - - PUGS_INLINE - SubArray(SubArray &&) = delete; - - PUGS_INLINE - ~SubArray() = default; -}; - -#endif // SUB_ARRAY_HPP diff --git a/tests/test_SubArray.cpp b/tests/test_SubArray.cpp deleted file mode 100644 index b0fdec7882d7ee3504cb24bdfb76b796649f8202..0000000000000000000000000000000000000000 --- a/tests/test_SubArray.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include <catch2/catch_test_macros.hpp> -#include <catch2/matchers/catch_matchers_all.hpp> - -#include <utils/PugsAssert.hpp> -#include <utils/SubArray.hpp> -#include <utils/Types.hpp> - -// Instantiate to ensure full coverage is performed -template class SubArray<int>; - -// clazy:excludeall=non-pod-global-static - -TEST_CASE("SubArray", "[utils]") -{ - Array<int> a(10); - REQUIRE(a.size() == 10); - - SECTION("shared values") - { - SubArray sub_a{a, 0, 10}; - for (size_t i = 0; i < sub_a.size(); ++i) { - sub_a[i] = 2 * i; - } - - REQUIRE(((a[0] == 0) and (a[1] == 2) and (a[2] == 4) and (a[3] == 6) and (a[4] == 8) and (a[5] == 10) and - (a[6] == 12) and (a[7] == 14) and (a[8] == 16) and (a[9] == 18))); - - for (size_t i = 0; i < a.size(); ++i) { - a[i] = (i + 1) * (2 * i + 1); - } - - REQUIRE(((sub_a[0] == 1) and (sub_a[1] == 6) and (sub_a[2] == 15) and (sub_a[3] == 28) and (sub_a[4] == 45) and - (sub_a[5] == 66) and (sub_a[6] == 91) and (sub_a[7] == 120) and (sub_a[8] == 153) and (sub_a[9] == 190))); - } - - SECTION("sub array") - { - a.fill(0); - SubArray sub_a{a, 5, 5}; - for (size_t i = 0; i < sub_a.size(); ++i) { - sub_a[i] = i + 1; - } - - REQUIRE(((a[0] == 0) and (a[1] == 0) and (a[2] == 0) and (a[3] == 0) and (a[4] == 0) and (a[5] == 1) and - (a[6] == 2) and (a[7] == 3) and (a[8] == 4) and (a[9] == 5))); - - for (size_t i = 0; i < a.size(); ++i) { - a[i] = (i + 1) * (2 * i + 1); - } - - REQUIRE(((sub_a[0] == 66) and (sub_a[1] == 91) and (sub_a[2] == 120) and (sub_a[3] == 153) and (sub_a[4] == 190))); - } - -#ifndef NDEBUG - SECTION("errors") - { - a.fill(0); - SubArray<int> sub_a{a, 5, 5}; - for (size_t i = 0; i < sub_a.size(); ++i) { - sub_a[i] = i + 1; - } - - REQUIRE_THROWS_AS(sub_a[5], AssertError); - } -#endif // NDEBUG -}