[libcxx-commits] [libcxx] [String] Allow fancy pointer as pointer type of basic_string allocator (PR #191023)
Nikita Belenkiy via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 17 07:05:27 PDT 2026
================
@@ -444,6 +445,235 @@ TEST_CONSTEXPR_CXX20 thread_unsafe_shared_ptr<T> make_thread_unsafe_shared(Args.
}
} // namespace detail
+template <class T>
+class fancy_pointer {
+public:
+ // For the std::pointer_traits interface.
+ using pointer = T*;
+ using element_type = T;
+ using difference_type = std::ptrdiff_t;
+
+ template <class U>
+ using rebind = fancy_pointer<U>;
+
+ // For the std::iterator_traits interface.
+ using value_type = typename std::remove_cv<T>::type;
+ using reference = typename std::add_lvalue_reference<T>::type;
+ using iterator_category = std::random_access_iterator_tag;
+
+ TEST_CONSTEXPR_CXX14 fancy_pointer() TEST_NOEXCEPT : ptr_(nullptr) {}
+ TEST_CONSTEXPR_CXX14 fancy_pointer(T* p) TEST_NOEXCEPT : ptr_(p) {}
+
+ template <typename T2>
+ TEST_CONSTEXPR_CXX14 explicit fancy_pointer(const fancy_pointer<T2>& other) TEST_NOEXCEPT
+ : ptr_(static_cast<T*>(other.get())) {}
+
+ TEST_CONSTEXPR_CXX14 operator T*() const TEST_NOEXCEPT { return ptr_; }
+ TEST_CONSTEXPR_CXX14 fancy_pointer(fancy_pointer&&) TEST_NOEXCEPT = default;
+ TEST_CONSTEXPR_CXX14 fancy_pointer(const fancy_pointer&) TEST_NOEXCEPT = default;
+ TEST_CONSTEXPR_CXX14 fancy_pointer& operator=(fancy_pointer&&) TEST_NOEXCEPT = default;
+ TEST_CONSTEXPR_CXX14 fancy_pointer& operator=(const fancy_pointer&) TEST_NOEXCEPT = default;
+ TEST_CONSTEXPR_CXX20 ~fancy_pointer() TEST_NOEXCEPT = default;
----------------
kitsnet wrote:
Done.
https://github.com/llvm/llvm-project/pull/191023
More information about the libcxx-commits
mailing list