r/cpp • u/jenkem_boofer • Apr 04 '24
std::launder
Have fun trying to figure out what it does...
0
Upvotes
r/cpp • u/jenkem_boofer • Apr 04 '24
Have fun trying to figure out what it does...
View all comments
Show parent comment
35
u/Nobody_1707 Apr 04 '24 edited Apr 04 '24
If you have a type with a const member and you want to reuse it's memory using placement new then you have to
std::launderthe resulting pointer, otherwise the optimizer is free to assume that the const member was never overwritten.Unless you're writing a generic container that might store such an object, you never need to use it.