C++ Logo


Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 18 Dec 2023 20:11:16 +0000
On Mon, Dec 18, 2023 at 4:55 PM Thiago Macieira wrote:
> There shouldn't be unaligned versions. The parameters should be plain T
> pointers.

'std::unaligned' will need to relocate an object into (and back out
of) unaligned space, and therefore we need an void* or byte*.

> T may be std::unaligned<X>, but that's a special-casing scenario and shouldn't
> require any code on the part of the user: std::unaligned's template relocator
> (however that is implemented) should just DTRT.

Here's my latest code using the libstdc++ that has an 'std::string'
that is _not_ trivially relocatable:


By the way I was thinking it would be cool if every class
automatically had "void ::_Relocate(void*,void*)" as a friend, so that
people can write the relocation function for libraries that were
written years ago (before the idea of relocation came up).

I've always thought though that it would be nice to be able to do the following:

    void Func( std::string &s )
        friend std::string; // Now we can access all the private
and protected members
        char *p = s._M_local_data;

Received on 2023-12-18 20:11:10