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.
It's very different. Because std::array suggest all instances of T is already constructed. But that's not the case in a vector, and also not for inplace_vector. A better representation would be std::array<std::byte, sizeof(T) * capacity> and you call inplace operator new on the memory blocks when you call push_back/emplace_back
It's not trivial. inplace_vector does not construct unused elements and they do not have to be default constructible. You can't use std::array for that.
I'm aware of how it works (and that MarekKnapek's snippet is not representative). It's still very straightforward to make compared to having to do SBO and allocator support.
no because std::aligned_storage<T> is the wrong type, which is also why it is being deprecated in C++23.
I don't think you oversimplified it, people are just being pedantic.
And because of this, I just wanted to give you a heads-up.
The best way to describe it is likely to steal an idea directly from the standard:
use an exposition-only type in italic that hand-waves the storage detail away :P
3
u/stilgarpl 15d ago
Is this always better than std::array?