[ub] new revision of p0593

Gabriel Dos Reis gdr at microsoft.com
Mon Feb 12 04:22:55 CET 2018


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 open-std.org] On Behalf Of Richard Smith
Sent: Friday, February 9, 2018 2:54 PM
To: ub <ub at open-std.org>
Subject: Re: [ub] new revision of p0593

On Fri, 9 Feb 2018 at 14:15, Jens Maurer <Jens.Maurer at gmx.net<mailto:Jens.Maurer at gmx.net>> 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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/ub/attachments/20180212/d405912f/attachment.html 


More information about the ub mailing list