MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1vzc5dg/c26_stdinplace_vector/p67jjmg/?context=3
r/cpp • u/User_Deprecated • 6d ago
121 comments sorted by
View all comments
4
Is this always better than std::array?
19 u/MarekKnapek 6d ago This is basically struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; } 3 u/stilgarpl 5d ago No, it's not. In your code it will always construct all T members of arr. Article states that inplace_vector will only have the elements needed and they don't have to be default constructible. That's a huge difference. 3 u/BenFrantzDale 5d ago Plus this is a `std::ranges::sized_range` with dynamic size, which `std::array` is not.
19
This is basically
struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; }
3 u/stilgarpl 5d ago No, it's not. In your code it will always construct all T members of arr. Article states that inplace_vector will only have the elements needed and they don't have to be default constructible. That's a huge difference. 3 u/BenFrantzDale 5d ago Plus this is a `std::ranges::sized_range` with dynamic size, which `std::array` is not.
3
No, it's not. In your code it will always construct all T members of arr. Article states that inplace_vector will only have the elements needed and they don't have to be default constructible. That's a huge difference.
3 u/BenFrantzDale 5d ago Plus this is a `std::ranges::sized_range` with dynamic size, which `std::array` is not.
Plus this is a `std::ranges::sized_range` with dynamic size, which `std::array` is not.
4
u/stilgarpl 6d ago
Is this always better than std::array?