C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::typeless_memory (type punning)

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 30 Nov 2024 11:15:52 +0000
On Sat, 30 Nov 2024, 09:56 James via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> Currently you can do whatever you want at runtime when it comes to type
> punning.
>

That's not exactly true.


Sure, all of them might not be safe, but you have some ways to do it
> safely. However in compile time (as far as I know) there is no way to
> achieve type punning.
>

See https://wg21.link/p3074


> So I'd like to see this type, in standard library
> https://godbolt.org/z/1dEjYW1hW
>
> It's only purpose is to allow treating some underlying memory as whatever
> type you want in compile time without using extra memory. It would also
> provide a shortcut for runtime usage
> Currently you can't achieve that due to placement new and reinterpret_cast
> not being usable in compile time context
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-11-30 11:17:13