MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1vzc5dg/c26_stdinplace_vector/p67jdtz/?context=3
r/cpp • u/User_Deprecated • 6d ago
121 comments sorted by
View all comments
1
Is this always better than std::array?
20 u/MarekKnapek 6d ago This is basically struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; } 5 u/drjeats 6d ago Oh. I thought this was the way-more-useful thing where you give it an in-place capacity and it allocates once it exceeds that. Like this is also useful, but it's kinda trivial to roll your own of this. 4 u/BenFrantzDale 5d ago It’s not too hard to roll your own, but better to have in the std lib and making it constexpr is tricky. There is a boost small_vector that is a small-vector-optimized std::vector so can grow large. There’s totally a place for both.
20
This is basically
struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; }
5 u/drjeats 6d ago Oh. I thought this was the way-more-useful thing where you give it an in-place capacity and it allocates once it exceeds that. Like this is also useful, but it's kinda trivial to roll your own of this. 4 u/BenFrantzDale 5d ago It’s not too hard to roll your own, but better to have in the std lib and making it constexpr is tricky. There is a boost small_vector that is a small-vector-optimized std::vector so can grow large. There’s totally a place for both.
5
Oh.
I thought this was the way-more-useful thing where you give it an in-place capacity and it allocates once it exceeds that.
Like this is also useful, but it's kinda trivial to roll your own of this.
4 u/BenFrantzDale 5d ago It’s not too hard to roll your own, but better to have in the std lib and making it constexpr is tricky. There is a boost small_vector that is a small-vector-optimized std::vector so can grow large. There’s totally a place for both.
4
It’s not too hard to roll your own, but better to have in the std lib and making it constexpr is tricky.
There is a boost small_vector that is a small-vector-optimized std::vector so can grow large. There’s totally a place for both.
1
u/stilgarpl 6d ago
Is this always better than std::array?