-
Notifications
You must be signed in to change notification settings - Fork 794
Open
Description
I think p10 could need an example, ideally on which highlights the idiom of using std::launder
to force the creation of one particular type of object.
int x;
new (storage) std::byte[sizeof(x)]; // implicitly begin the lifetime of objects in x
*reinterpret_cast<char*>(&x); // unspecified whether placement new created
// an int object inside x, float, char[], or any other objects
std::memmove(&x, &x, sizeof(x)); // transparently replace ([basic.life]) x with another object
x = 0; // the new object must be of type (no cv) int because
// only that may give the program well-defined behavior
std::memmove(&x, &x, sizeof(x)); // begin the lifetime of one or multiple objects in the storage of x
std::launder(reinterpret_cast<short*>(&x)); // created object at &x must be of type short int
x = 0; // undefined behavior
Metadata
Metadata
Assignees
Labels
No labels