Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++object lifetime and std::launderSingle-choice MCQ

You memcpy the bytes of a serialized `int` into a buffer of `unsigned char` and want to read it as an `int` without invoking the constructor. C++23 added `std::start_lifetime_as`. What does that function do that a bare `reinterpret_cast` plus `std::launder` does not, for an implicit-lifetime type?

unsigned char buf[sizeof(int)]; // bytes of an int already copied into buf via memcpy int v = *std::start_lifetime_as<int>(buf);