Date: Fri, 29 Sep 2023 13:27:57 +0100
Would anyone be interested in working on a proposal to add constexpr
functionality to std::shared_ptr. An implementation based on libstdc++ is
linked below:
https://github.com/SCT4SP/constexpr_shared_ptr
For convenience, `_GLIBCXX26_CONSTEXPR` and feature macro
`__cpp_lib_constexpr_shared_ptr` have been defined and used throughout.
The implementation takes advantage of recent support in GCC and Clang for
P2738 (constexpr cast from void*: towards constexpr type-erasure). Beyond
that we have the usual avoidance of placement new with
`allocator_traits::construct` etc.; `std::is_constant_evaluated` allows
avoidance of atomic operations; and `std::make_shared`,
`std::allocate_shared` and variants have required two separate allocations
to avoid illegal pointer casting.
Comments welcome.
functionality to std::shared_ptr. An implementation based on libstdc++ is
linked below:
https://github.com/SCT4SP/constexpr_shared_ptr
For convenience, `_GLIBCXX26_CONSTEXPR` and feature macro
`__cpp_lib_constexpr_shared_ptr` have been defined and used throughout.
The implementation takes advantage of recent support in GCC and Clang for
P2738 (constexpr cast from void*: towards constexpr type-erasure). Beyond
that we have the usual avoidance of placement new with
`allocator_traits::construct` etc.; `std::is_constant_evaluated` allows
avoidance of atomic operations; and `std::make_shared`,
`std::allocate_shared` and variants have required two separate allocations
to avoid illegal pointer casting.
Comments welcome.
-- Paul
Received on 2023-09-29 12:28:12