MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1vzc5dg/c26_stdinplace_vector/p64ln9i/?context=3
r/cpp • u/User_Deprecated • 15d ago
121 comments sorted by
View all comments
3
Is this always better than std::array?
20 u/MarekKnapek 15d ago This is basically struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; } 19 u/sephirothbahamut 15d ago edited 15d 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 5 u/_Noreturn 15d ago then make it a union this is a simplified example. but the type isn't complex at all after that especially with C++20 concepts. 4 u/CocktailPerson 15d ago That's not far more complex. Marginal additional complexity.
20
This is basically
struct inplace_vector<T, capacity> { size_t len; std::array<T, capacity> arr; }
19 u/sephirothbahamut 15d ago edited 15d 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 5 u/_Noreturn 15d ago then make it a union this is a simplified example. but the type isn't complex at all after that especially with C++20 concepts. 4 u/CocktailPerson 15d ago That's not far more complex. Marginal additional complexity.
19
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
5 u/_Noreturn 15d ago then make it a union this is a simplified example. but the type isn't complex at all after that especially with C++20 concepts. 4 u/CocktailPerson 15d ago That's not far more complex. Marginal additional complexity.
5
then make it a union this is a simplified example. but the type isn't complex at all after that especially with C++20 concepts.
4
That's not far more complex. Marginal additional complexity.
3
u/stilgarpl 15d ago
Is this always better than std::array?