Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any useful difference between std::bit_cast and std::start_lifetime_as?

std::bit_cast is apparently being introduced in c++20. and std::start_lifetime_as is proposed for c++23 (from P0593R5). As they appear to both require that the datatypes involved be trivial anyways, will there be any need for the former once the latter is introduced?

Apologies in advance for not providing any more information about these new features. I only just heard about them after watching a cppcon 2019 lecture on type-punning, and I wasn't able to find much about start_lifetime_as with google. I'm hoping someone else who sees this might know more.

like image 481
markt1964 Avatar asked Dec 03 '22 10:12

markt1964


1 Answers

The answer is trivial: bit_cast returns a value, whereas start_lifetime_as “alters” memory (in a way that exists in the abstract machine but is not expected to affect any physical bits). You use the former to (once) interpret an existing object as a set of bits; you use the latter to (permanently) interpret existing bits as an object.

like image 118
Davis Herring Avatar answered Dec 23 '22 01:12

Davis Herring