Skip to content
Snippets Groups Projects
Commit 9c8a7c44 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix constructors

- remove a useless static_assert in the standard constructor
- forbid default constructor: SubArray require an Array to exist
parent e8b20dee
No related branches found
No related tags found
1 merge request!84Add SubArray class
...@@ -75,12 +75,10 @@ class [[nodiscard]] SubArray ...@@ -75,12 +75,10 @@ class [[nodiscard]] SubArray
: m_array{array}, m_sub_values{&array[0] + begin}, m_size{size} : m_array{array}, m_sub_values{&array[0] + begin}, m_size{size}
{ {
Assert(begin + size <= array.size(), "SubView is not contained in the source Array"); Assert(begin + size <= array.size(), "SubView is not contained in the source Array");
static_assert(not std::is_const<DataType>(), "Cannot allocate SubArray of const data: only view is "
"supported");
} }
PUGS_INLINE PUGS_INLINE
SubArray() = default; SubArray() = delete;
PUGS_INLINE PUGS_INLINE
SubArray(const SubArray&) = default; SubArray(const SubArray&) = default;
......
...@@ -54,7 +54,7 @@ TEST_CASE("SubArray", "[utils]") ...@@ -54,7 +54,7 @@ TEST_CASE("SubArray", "[utils]")
SECTION("sub array copy") SECTION("sub array copy")
{ {
a.fill(0); a.fill(0);
SubArray<int> sub_a; SubArray<int> sub_a{a, 2, 1};
sub_a = SubArray{a, 5, 5}; sub_a = SubArray{a, 5, 5};
for (size_t i = 0; i < sub_a.size(); ++i) { for (size_t i = 0; i < sub_a.size(); ++i) {
sub_a[i] = i + 1; sub_a[i] = i + 1;
...@@ -95,7 +95,7 @@ TEST_CASE("SubArray", "[utils]") ...@@ -95,7 +95,7 @@ TEST_CASE("SubArray", "[utils]")
SECTION("errors") SECTION("errors")
{ {
a.fill(0); a.fill(0);
SubArray<int> sub_a; SubArray<int> sub_a{a, 0, 0};
sub_a = SubArray{a, 5, 5}; sub_a = SubArray{a, 5, 5};
for (size_t i = 0; i < sub_a.size(); ++i) { for (size_t i = 0; i < sub_a.size(); ++i) {
sub_a[i] = i + 1; sub_a[i] = i + 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment