@lemire Another approach is to pass a generic lambda to itself as continuation:
auto fact = [](auto self, int n) {
if (n == 0) {
return 1;
} else {
return n * self(self, n - 1);
}
};
fact(fact, 10)
@__phantomderp You can probably save up on space for that 0-terminator if instead of size you maintain (capacity-size) right after the data. This way once size reaches capacity, a zero byte after data will be both a terminator and part of correct (capacity-size)
@AyxanHaqverdili@shafikyaghmour To add some cursedness, I believe there's no need for immediately invoked lambda, a conditional operator should work as well
@rationaleks@outofcontextlog если интересно, вот вики glibc https://t.co/JjKjFs4KxB , а вот лекция Фёдора Короткого про jemalloc https://t.co/qn0RLJqSfI
@PeterSommerlad Something like static_vector<std::array<int, N>, M>
It's trivially destructible yet may be expensive to move all the elements
@PeterSommerlad I feel like I should elaborate. There may be cases when default destructor is O(1) because the members are trivially destructible. We may however want an optimized implementation for move when we expect that usually only a part of the members need to be moved/copied