Skip to content

Commit 88b6248

Browse files
committed
FixedVector:resize()
1 parent 3569ba4 commit 88b6248

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
@@ -34,6 +34,20 @@ public:
3434
return true;
3535
}
3636

37+
// Resizes
38+
bool resize(size_t num, T el = T{}) {
39+
const auto new_back_idx = std::min(num, MaxElements);
40+
41+
if (new_back_idx > back_idx) {
42+
for (auto i = back_idx; i < new_back_idx; i++) {
43+
data[i] = el;
44+
}
45+
}
46+
47+
back_idx = new_back_idx;
48+
return (num == new_back_idx);
49+
}
50+
3751
// returns MaxElements for failure
3852
size_t push_back_for_overwrite() {
3953
if (back_idx >= MaxElements)

0 commit comments

Comments
 (0)