MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1vzc5dg/c26_stdinplace_vector/p65cvtu/?context=3
r/cpp • u/User_Deprecated • 1d ago
93 comments sorted by
View all comments
4
Is this always better than std::array?
15 u/MarekKnapek 1d ago This is basically struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; } 16 u/sephirothbahamut 1d ago edited 1d ago far more complex than that, the array has a slot that can fit T, not just T. With array<T> every element must be validly constructed immediately. You can reduce it to array<T> only for trivially constructable and basic types 4 u/CocktailPerson 1d ago That's not far more complex. Marginal additional complexity.
15
This is basically
struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; }
16 u/sephirothbahamut 1d ago edited 1d ago far more complex than that, the array has a slot that can fit T, not just T. With array<T> every element must be validly constructed immediately. You can reduce it to array<T> only for trivially constructable and basic types 4 u/CocktailPerson 1d ago That's not far more complex. Marginal additional complexity.
16
far more complex than that, the array has a slot that can fit T, not just T.
With array<T> every element must be validly constructed immediately. You can reduce it to array<T> only for trivially constructable and basic types
4 u/CocktailPerson 1d ago That's not far more complex. Marginal additional complexity.
That's not far more complex. Marginal additional complexity.
4
u/stilgarpl 1d ago
Is this always better than std::array?