See https://godbolt.org/z/Ta85r4a7e. Basically the problem is in the use of placement new (C++ does not allow to use pointer to const for the address). There is std::construct_at for such cases. For example look how std::optional is implemented in the libc++:
See https://godbolt.org/z/Ta85r4a7e. Basically the problem is in the use of placement new (C++ does not allow to use pointer to const for the address). There is
std::construct_at
for such cases. For example look howstd::optional
is implemented in the libc++:https://github.com/llvm/llvm-project/blob/3791b3fca6eac5e403b91550ed0f774866cf3ede/libcxx/include/optional#L419 https://github.com/llvm/llvm-project/blob/3791b3fca6eac5e403b91550ed0f774866cf3ede/libcxx/include/__memory/construct_at.h#L49-L54 https://github.com/llvm/llvm-project/blob/3791b3fca6eac5e403b91550ed0f774866cf3ede/libcxx/include/__memory/voidify.h#L25