Add std::inplace_vector polyfill from c++26 [NFC]#8814
Conversation
|
|
||
| #include "support/parent_index_iterator.h" | ||
|
|
||
| namespace std { |
There was a problem hiding this comment.
It's UB in most cases to add things to std, we should not do that here. Not to mention there are several behavioral differences between this implementation and the standard, especially around when constructors and destructors are called on the elements.
| EXPECT_EQ(vec[0], 10); | ||
|
|
||
| vec.resize(3); | ||
| EXPECT_EQ(vec.size(), 3); |
There was a problem hiding this comment.
We should also check that the size is 0 and then 1 before doing this resize.
| inplace_vector(inplace_vector<T, N>&& other) | ||
| : usedFixed(other.usedFixed), fixed(std::move(other.fixed)) {} | ||
| inplace_vector(std::initializer_list<T> init) { | ||
| for (T item : init) { |
There was a problem hiding this comment.
Should we loop through const T& to avoid a copy here? It looks like we're doing 2 copies per element here (once in the loop iteration and a second one in push_back).
There was a problem hiding this comment.
Good idea, this is copied from SmallVector but I'll improve it there too.
|
Also the fuzzer found I misread the CFP code - the size is not limited to 2 there (each call to handleType is limited, but we call it multiple times). So this adds no uses of the class, for now. |
Header is basically our SmallVector, modified to remove the dynamic
allocation.
This is already useful in one place, and will help more with a future PR.