Skip to content

Commit 6f7a4e9

Browse files
committed
FixedVector::resize_for_overwrite, span
1 parent 88b6248 commit 6f7a4e9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

util/fixed_vector.hh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <array>
44
#include <cstddef>
55
#include <iterator>
6+
#include <span>
67

78
template<typename T, size_t MaxElements>
89
class FixedVector {
@@ -48,6 +49,11 @@ public:
4849
return (num == new_back_idx);
4950
}
5051

52+
bool resize_for_overwrite(size_t num) {
53+
back_idx = std::min(num, MaxElements);
54+
return (num == back_idx);
55+
}
56+
5157
// returns MaxElements for failure
5258
size_t push_back_for_overwrite() {
5359
if (back_idx >= MaxElements)
@@ -138,4 +144,12 @@ public:
138144
auto end() {
139145
return begin() + back_idx;
140146
}
147+
148+
auto span() {
149+
return std::span{begin(), back_idx};
150+
}
151+
152+
auto span() const {
153+
return std::span{begin(), back_idx};
154+
}
141155
};

0 commit comments

Comments
 (0)