3 ms·
Thanks for the link! I got confused because your cppreference link only talks about std::launder. I did not know about std::start_lifetime_as. Looks very usefu
by spacechild1 4y ago
Thanks for the link! I got confused because your cppreference link only talks about std::launder.
I did not know about std::start_lifetime_as. Looks very useful! It's crazy that it took so long. Considering that one of the primary design goals of C++ was backwards compatibility with C (too a large extent), I always found it crazy that malloc'ing objects would be undefined behavior. In practice, this has always worked, though. At least now we have a standard-blessed way to do these kind of things.
As a side note, does this mean that you can finally cast an array of bytes to an object pointer (e.g. for deserialization) without violating strict-aliasing rules? The usage example in section 1.2 of the linked paper seems to imply this, but it does not mention aliasing anywhere...
- pjmlp 4y agoI guess this is also interesting to watch, "Taking a Byte Out of C++ - Avoiding Punning by Starting Lifetimes - CppCon 2022" https://www.youtube.com/watch?v=pbkQG09grFw https://www.youtube.com/watch?v=pbkQG09grFw