diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-14 13:20:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-14 13:20:49 +0200 |
commit | 6f45f8555be7bef45b7c50a95b898ebba7fb9a92 (patch) | |
tree | f2f7c24b74d647db470002974f38af14fff8bc8f /compat | |
parent | ec67a7720a236918188b384c95631c4a5f1abb3c (diff) |
w
Diffstat (limited to 'compat')
-rw-r--r-- | compat/borrowed-ptr.hpp | 10 | ||||
-rw-r--r-- | compat/borrowed-ptr.inl | 17 |
2 files changed, 12 insertions, 15 deletions
diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index affad912..3982b547 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -31,8 +31,6 @@ class bptr final // NOLINT(*-special-member-functions) { detail_borrowed_ptr::control_block* blk; - bptr(detail_borrowed_ptr::control_block* blk) noexcept; - template<typename Y> bptr(const bptr<Y>& other, std::nullptr_t) noexcept; template<typename Y> bptr& _copy_assign(const bptr<Y>& other) noexcept; template<typename Y> bptr(bptr<Y>&& other, std::nullptr_t) noexcept; @@ -52,13 +50,13 @@ public: bptr(const bptr&) noexcept; bptr& operator=(const bptr&) noexcept; - template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> bptr(const bptr<Y>&) noexcept; - template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> bptr& operator=(const bptr<Y>&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr(const bptr<Y>&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr& operator=(const bptr<Y>&) noexcept; bptr(bptr&&) noexcept; bptr& operator=(bptr&&) noexcept; - template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> bptr(bptr<Y>&&) noexcept; - template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> bptr& operator=(bptr<Y>&&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr(bptr<Y>&&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr& operator=(bptr<Y>&&) noexcept; operator bptr<const T>() const noexcept requires (!std::is_const_v<T>); diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index acdcb0df..c2a8b730 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -43,14 +43,16 @@ template<typename T> template<typename... Ts> requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...> bptr<T>::bptr(InPlaceInitT, Ts&&... args) noexcept: -bptr{ new T{ forward<Ts...>(args...) } } +bptr{ new std::remove_const_t<T>{ forward<Ts...>(args)... } } { } template<typename T> bptr<T>::bptr(std::nullptr_t) noexcept: blk{nullptr} {} template<typename T> bptr<T>::bptr() noexcept: bptr{nullptr} {} -template<typename T> bptr<T>::bptr(T* ptr) noexcept: blk{ptr ? new detail_borrowed_ptr::control_block{ptr, 1} : nullptr} {} +template<typename T> bptr<T>::bptr(T* ptr) noexcept: + blk{ptr ? new detail_borrowed_ptr::control_block{const_cast<std::remove_const_t<T>*>(ptr), 1} : nullptr} +{} template<typename T> bptr<T>::~bptr() noexcept @@ -63,11 +65,11 @@ template<typename T> bptr<T>::bptr(const bptr& other) noexcept: bptr{other, null template<typename T> bptr<T>& bptr<T>::operator=(const bptr& other) noexcept { return _copy_assign(other); } template<typename T> -template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> +template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr<T>::bptr(const bptr<Y>& other) noexcept: bptr{other, nullptr} {} template<typename T> -template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> +template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr<T>& bptr<T>::operator=(const bptr<Y>& other) noexcept { return _copy_assign(other); } @@ -75,11 +77,11 @@ template<typename T> bptr<T>& bptr<T>::operator=(bptr&& other) noexcept { return template<typename T> bptr<T>::bptr(bptr&& other) noexcept: bptr{move(other), nullptr} {} template<typename T> -template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> +template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr<T>::bptr(bptr<Y>&& other) noexcept: bptr{move(other), nullptr} {} template<typename T> -template<detail_borrowed_ptr::DerivedFrom<std::remove_const_t<T>> Y> +template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr<T>& bptr<T>::operator=(bptr<Y>&& other) noexcept { return _move_assign(move(other)); } @@ -115,9 +117,6 @@ void bptr<T>::destroy() noexcept template<typename T> bptr<T>& bptr<T>::operator=(std::nullptr_t) noexcept { reset(); return *this; } template<typename T> -bptr<T>::bptr(detail_borrowed_ptr::control_block* blk) noexcept: blk{blk} { } - -template<typename T> template<typename Y> bptr<T>::bptr(const bptr<Y>& other, std::nullptr_t) noexcept: blk{other.blk} |