C++ Logo

std-proposals

Advanced search

Re: P1839 and the object representation of subobjects

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Tue, 21 Jul 2020 23:31:02 +0200
Il 21/07/20 17:01, Jason McKesson via Std-Proposals ha scritto:
> We technically already have a way to do that: `std::launder`:
>
> ```
> auto byte_ptr = reinterpret_cast<byte *>(qoptr);
> auto c1ptr = std::launder(reinterpret_cast<C1 *>(qoptr + off);
> ```
>
> If there is an object of type `C1` at the given address, then
> `std::launder` will return a pointer to it. This is the purpose of
> `launder`.

I'm not 100% sure that P1839 would allow for the above reintepret_cast,
though. And if it does, would std::launder still be necessary?

Thanks for the insight,
-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2020-07-21 16:34:26