4 ms·
This is how it's being done in one of the places: new (ptr) T; // default-initialization of T *ptr = T(std::forward<Args>(args)...); // Constructs a ne
by Matheus28 5y ago
This is how it's being done in one of the places:
new (ptr) T; // default-initialization of T
*ptr = T(std::forward<Args>(args)...); // Constructs a new T, then calls operator=(T&&) on ptr, then destroys the T that got moved
I meant he should do the placement new like this:
new (ptr) T(std::forward<Args>(args)...) // Constructs directly on ptr
See https://godbolt.org/z/9nT94zxoE https://godbolt.org/z/9nT94zxoE