While immersed in dynamic memory, it seemed contradictory to me how trivial types begin their lives. Consider a fragment
void* p = ::operator new(sizeof(int)); // 1 // 2 new (p) int; // 3
When intdoes your life begin?
int
Only acquires memory, is ::operator newindicated to have an effect (from [new.delete.single] )
::operator new
Distribution functions called by the new expression to allocate bytes of memory size. [...] allocates storage properly aligned to represent any object of this size if the type of the object does not have alignment with the extension extension.
Given that it is not enough to create an object , intit cannot begin to exist here.
At this point, storage was purchased for lampshades for int.
intcreated by placing new. But for some reason, his life here did not begin, since from [basic.life]
[...] They say that an object has non-empty initialization if it belongs to a class or an aggregate, and it or one of its subobjects is initialized with a constructor other than the trivial default constructor. The lifetime of an object of type Tbegins when:the storage with the correct alignment and size for the type is Treceived, andif the object has a non-empty initialization, its initialization is completed [...]
[...] They say that an object has non-empty initialization if it belongs to a class or an aggregate, and it or one of its subobjects is initialized with a constructor other than the trivial default constructor. The lifetime of an object of type Tbegins when:
T
the storage with the correct alignment and size for the type is Treceived, and
if the object has a non-empty initialization, its initialization is completed [...]
int , , . . , , , , .
. . a.allocate(n) a - T
a.allocate(n)
a
n T, .
n
, . new(p) int , [basic.life]/1, , new(p) int .
new(p) int
N4659 [expr.new] new(p) int ::operator new(sizeof(int), p). [new.delete.placement] ââ:
::operator new(sizeof(int), p)
void* operator new(std::size_t size, void* ptr) noexcept;: ptr.: .
void* operator new(std::size_t size, void* ptr) noexcept;
: ptr.
: .
" " , , , , - , .