FWI, std::basic_string<long
double> is not a well chosen example as 'long double' is not a character container type: std::char_traits<long double> need not be defined by an implementation (and should probably not be). The primary template for std::char_traits could as well be left undefined.

At least, it would be more appealing to use a more sensible type as a toy example, say std::u32string (AKA std::basic_string<char32_t>).

Julien V.

On December 20, 2023 12:22:52 p.m. EST, Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On Wed, Dec 20, 2023 at 1:39 PM Frederick Virchanza Gotham wrote:

Tested and working: https://godbolt.org/z/qK736evY7

Here's my latest implementation of 'std::unaligned' that has a
specialisation of the '_Relocate' function which should work fine with
libstdc++'s nonrelocatable implementation of 'basic_string'. The test
code works fine with 'std::string' and also 'std::basic_string<long


By the way I think the standard library should have a function to test
the alignment of a pointer:

template<typename T>
inline std::ptrdiff_t alignment_modulus(void const *const arg) noexcept
assert( nullptr != arg );
#ifdef UINTPTR_MAX // If this compiler has std::uintptr_t
return reinterpret_cast<std::uintptr_t>(arg) % alignof(T);
// This implementation does not need std::uintptr_t (which
might not exist)
using std::byte;
std::ptrdiff_t retval = alignof(T);
byte *p = static_cast<byte*>(const_cast<void*>(arg));
std::size_t buffer_size = sizeof(T);
for ( ; ; ++p, --retval )
if ( nullptr != std::align(alignof(T), sizeof(T),
*static_cast<void**>(static_cast<void*>(p)), buffer_size) )
return retval % alignof(T);