Skip to content

Commit c2c226d

Browse files
author
Lukas Thomann
committed
fixed an infinite recursion bug and clarified naming in poly_vector
1 parent ab390e0 commit c2c226d

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

cth/incl/cth/data/poly_vector.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,36 @@ class raw_poly_vector {
7070
if(offset == 0)
7171
return;
7272

73-
data() = static_cast<std::byte*>(::operator new(offset, ALLOC_ALIGN));
73+
data_ref() = static_cast<std::byte*>(::operator new(offset, ALLOC_ALIGN));
7474

7575
for(size_t i = 0; i < N; ++i)
76-
_begins[i] = data() + byteOffsets[i];
76+
_begins[i] = data_ref() + byteOffsets[i];
7777
}
7878

7979
void swap(this raw_poly_vector& s, raw_poly_vector& other) { std::swap(s._begins, other._begins); }
8080

8181
private:
8282
constexpr void free() {
83-
if(data() == nullptr)
83+
if(data_ref() == nullptr)
8484
return;
8585

86-
::operator delete(data(), ALLOC_ALIGN);
86+
::operator delete(data_ref(), ALLOC_ALIGN);
8787
}
8888

8989
std::array<base_t*, N> _begins{};
9090

91-
base_t*& data() { return _begins[0]; }
91+
base_t*& data_ref() { return _begins[0]; }
9292

9393
public:
9494
constexpr raw_poly_vector(raw_poly_vector const& other) = delete;
9595
constexpr raw_poly_vector& operator=(raw_poly_vector const& other) = delete;
96-
constexpr raw_poly_vector(raw_poly_vector&& other) noexcept { std::swap(*this, other); }
96+
constexpr raw_poly_vector(raw_poly_vector&& other) noexcept : _begins{other._begins} {
97+
other.data_ref() = nullptr;
98+
}
9799
constexpr raw_poly_vector& operator=(raw_poly_vector&& other) noexcept {
98100
free();
99101
_begins = other._begins;
100-
other.data() = nullptr;
102+
other.data_ref() = nullptr;
101103
return *this;
102104
};
103105
};

0 commit comments

Comments
 (0)