C++ Logo

sg12

Advanced search

Re: [ub] new revision of p0593

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Mon, 12 Feb 2018 03:22:55 +0000
Can we combine both into a single facility as Jens suggests, even with we keep the two separate? That way, nobody gets to forget std::launder because most don’t get to write it in the first place.

From: ub-bounces_at_open-std.org [mailto:ub-bounces_at_[hidden]] On Behalf Of Richard Smith
Sent: Friday, February 9, 2018 2:54 PM
To: ub <ub_at_[hidden]>
Subject: Re: [ub] new revision of p0593

On Fri, 9 Feb 2018 at 14:15, Jens Maurer <Jens.Maurer_at_[hidden]<mailto:Jens.Maurer_at_[hidden]>> wrote:
On 02/09/2018 08:52 PM, Richard Smith wrote:
> Please find attached a revised version of P0593

Regarding std::bless in particular: While that's probably
a useful facility for stuff such as mmap, I'd actually
like to see a

  T * result = std::bless<T>(p)

which works as-if an object of type T were created at p,
reusing the existing values of the storage.

I think that's:

std::bless(p, sizeof(T));
T *result = std::launder(reinterpret_cast<T*>(p));

... assuming T is an implicit lifetime type. Packaging that up as a separate library function might be nice, though (your form is probably easier for humans and tools to reason about). Especially since it means we can enforce the implicit lifetime type requirement (otherwise I think people would be tempted to use this to implement things like node_handle, and it's not quite strong enough for that in general).

Received on 2018-02-12 04:23:07