By Blog Staff | Jul 2, 2026 01:05 PM | Tags: None

797f4c8c0b89b22b.pngIn today's post, I will continue with the overall topics of the last two months. Today you'll learn when and where you need to apply C++17's std::launder and where the difference to this utility is to reinterpret_cast or std::start_lifetime_as.

From Undefined to Defined: Using std::launder in C++

by Andreas Fertig

From the article:

The fields where you can apply today's learning vary. The embedded domain is usually one where std::launder is used, but if you're writing library code, laundering occurs as well.

When things may break

I'm using the example from the paper P0532R0:

struct X {
  const int n;  A
  double    d;
};

X* p = new X{7, 8.8};  B

new(p) X{42, 9.9};  C

int  i = p->n;  D
auto d = p->d;  E

You're looking at several different pieces that need to come together. Notice that the struct X declares the member n as const.

Next, with the help of new, an object is created in B and the resulting pointer is stored in p. So far, so good.

The interesting part starts next in C with the placement new. If you've never done this, great, then you might not need to do the laundry, at least not in your C++ code.