P3377R0 — constexpr `reinterpret_cast` partial replacements
Hana Dusíková, Gašper Ažman
EWGLEWG
| functionality | runtime only (current status) | runtime & constexpr compatible replacement | status | | --- | --- | --- | --- | | pointer ↔︎ integer | `intptr_t * iptr = reinterpret_cast<intptr_t>(ptr); auto * optr = reinterpret_cast<pointer>(iptr);` | — | not proposed | | pointer tagging | `auto tptr = reinterpret_cast<pointer>( reinterpret_cast<intptr_t>(ptr) \| 0b1u); auto tag = static_cast<bool>( reinterpret_cast<intptr_t>(tptr) & 0b1u); auto optr = reinterpret_cast<pointer>( reinterpret_cast<intptr_t>(tptr) & ~0b1u);` | `auto tptr = tagged_pointer<int *, bool, 1>{ptr}; auto tag = tptr.tag(); auto optr = tptr.pointer();` | [P3125](https://wg21.link/P3125) | | casting to enclosing type | `struct outer_t { int first; int second; }; outer_t outer{1,2}; auto * out1 = reinterpret_cast<outer_t *>(&outer.first); auto * out2 = reinterpret_cast<outer_t *>(&outer.second);` | `struct outer_t { int first; int second; }; outer_t outer{1,2}; auto & out1 = std::enclosing_cast<&outer_t::first_member>(outer.first); auto & out2 = std::enclosing_cast<&outer_t::second_member>(outer.second);` | ✔️ | | accessing bytes of an object | `auto * bytes = reinterpret_cast<std::byte *>(obj);` | — | not pr