C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[packed]] std::unaligned

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 14 Dec 2023 00:26:09 +0000
On Wed, Dec 13, 2023 at 8:13 PM Thiago Macieira wrote:
>
> Which makes this DoA because you need a copy constructor to keep the validity.
> libstdc++'s C++11 std::string contains a pointer that points back to the
> object, so this std::string isn't trivially relocatable.


Thiago you always do this. I spend about 4.2 seconds of my time and
half a picojoule of brain energy picking out an arbitrary type from
the standard library just to compose an example, and you latch onto it
and give an in-depth analysis of why it's lack-lustre.

std::unaligned should be trivially constructible if T is trivially
constructible, and it should be trivially destructible if T is
trivially destructible. For some people here on the mailing list,
that's enough and they don't want more. I wanted to go a step further
with it though and make it more versatile than that -- I think
std::unaligned should be able to work with pretty much any class.

I've taken my previous GodBolt and made two more changes:
(1) I've replaced 'sizeof' with '__datasizeof', and I've added an
implementation of 'mybitcast' -- as Arthur previously pointed out that
the bit_cast's will fail with __datasizeof(T)
(2) I've added a template constructor that works along the same lines
of 'emplace'.

Here's what I have now: https://godbolt.org/z/MzajK4j4c

Received on 2023-12-14 00:26:10