C++ Logo

std-proposals

Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 15 Dec 2023 11:13:17 -0500
On Fri, Dec 15, 2023 at 9:15 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:

>
> That [libstdc++] implementation of std::string could be given a new member
> function something like:
>
> void string::_Relocate(void *const p) noexcept {
> if ( (this->ptr >= this->buf) && (this->ptr < (this-> buf +
> sizeof(this->buf)) ) {
> this->ptr += (char*)p - (char*)this;
> }
> }
>
> Then we could write a constraint that detects the member function
> '_Relocate' and call it 'std::is_nontrivially_relocatable', and so then the
> template class 'std::unaligned' could have the following constraint:
>
> requires is_trivially_relocatable_v<T> ||
> is_nontrivially_relocatable_v<T>
>

In fact you could call it `is_relocatable_v<T>`. This idea has occurred to
others; see the bibliography of P1144, particularly
- Pablo Halpern's N4158: ADL `uninitialized_destructive_move`
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4158.pdf>
- Denis Bider's P0023: `>>T(T&)`
<https://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0023r0.pdf>
- Sébastien Bini and Ed Catmur's P2785: T(T)
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2785r3.html>

–Arthur

Received on 2023-12-15 16:13:31