Some types are defined by standard as implicit-lifetime types, and arrays are among them.
Some functions implicitly create objects with implicit-lifetime (malloc etc are among them),
with a list of operations that implicitly create objects with implicit lifetime, found here. https://en.cppreference.com/w/cpp/language/object (I hope it is correct, but for the rest of the question let's assume that new
works as malloc
in this case for implicit object creation purposes).
What does it mean to implicitly create an array if it doesn't create its elements? Does it mean that
T* implicit_array = reinterpret_cast<T*>(::operator new(sizeof(T) * count, std::align_val_t{alignof(T)}) );
produces implicit_array object that is suitable for pointer arithmetic in, namely provides valid storage for elements of type T to be constructed using placement new later?
Does it mean that new (implicit_array + i) T{...}
is a well defined operation, even though, by the standard, implicit_array + i
is not necessarily defined? https://eel.is/c++draft/expr.unary#op-3.2.
Or it means that
std::byte* memory =
reinterpret_cast<std::byte*>(::operator new(sizeof(T) * capacity, std::align_val_t{alignof(T)}));
new (memory) T{args1 ...}
// build more objects
new (memory + (k-1)*sizeof(T) ) T{args_k ...}
T* implicit_array = std::launder(reinterpret_cast<T*>(memory) ); // does it produce array of k elements?
treats implicit_array
as an array with k elements?
Thanks.