From 277da30e969b54f5f27d2d621fde12bacedaba27 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 14 Jul 2024 18:16:44 +0200 Subject: w --- compat/borrowed-ptr-fwd.hpp | 13 ++----- compat/borrowed-ptr.hpp | 47 ++++++++++++++++--------- compat/borrowed-ptr.inl | 86 ++++++++++++++++++++++----------------------- 3 files changed, 75 insertions(+), 71 deletions(-) diff --git a/compat/borrowed-ptr-fwd.hpp b/compat/borrowed-ptr-fwd.hpp index 5f9c09f4..6a3db763 100644 --- a/compat/borrowed-ptr-fwd.hpp +++ b/compat/borrowed-ptr-fwd.hpp @@ -4,16 +4,9 @@ namespace floormat { struct bptr_base; -template -requires std::is_convertible_v -class bptr; +template class bptr; -template -requires std::is_convertible_v -bptr(T* ptr) -> bptr; - -template -requires std::is_convertible_v -bptr(const T* ptr) -> bptr; +template bptr(T* ptr) -> bptr; +template bptr(const T* ptr) -> bptr; } // namespace floormat diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 34fa6cfe..6862af2e 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -31,37 +31,50 @@ struct bptr_base }; template -requires std::is_convertible_v class bptr final // NOLINT(*-special-member-functions) { detail_borrowed_ptr::control_block* blk; - template bptr(const bptr& other, std::nullptr_t) noexcept; + template + requires std::is_convertible_v + bptr(const bptr& other, std::nullptr_t) noexcept; + template bptr& _copy_assign(const bptr& other) noexcept; - template bptr(bptr&& other, std::nullptr_t) noexcept; + + template + requires std::is_convertible_v + bptr(bptr&& other, std::nullptr_t) noexcept; + template bptr& _move_assign(bptr&& other) noexcept; public: template - requires std::is_constructible_v, Ts&&...> + requires (std::is_constructible_v, Ts&&...> && std::is_convertible_v) explicit bptr(InPlaceInitT, Ts&&... args) noexcept; - explicit bptr(T* ptr) noexcept; - bptr() noexcept; + explicit bptr(T* ptr) noexcept requires std::is_convertible_v; + bptr() noexcept requires std::is_convertible_v; ~bptr() noexcept; - bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions) - bptr& operator=(std::nullptr_t) noexcept; + bptr(std::nullptr_t) noexcept requires std::is_convertible_v; // NOLINT(*-explicit-conversions) + bptr& operator=(std::nullptr_t) noexcept requires std::is_convertible_v; + + bptr(const bptr&) noexcept requires std::is_convertible_v; + bptr& operator=(const bptr&) noexcept requires std::is_convertible_v; + + template Y> bptr(const bptr&) noexcept + requires std::is_convertible_v; + + template Y> bptr& operator=(const bptr&) noexcept + requires std::is_convertible_v; - bptr(const bptr&) noexcept; - bptr& operator=(const bptr&) noexcept; - template Y> bptr(const bptr&) noexcept; - template Y> bptr& operator=(const bptr&) noexcept; + bptr(bptr&&) noexcept requires std::is_convertible_v; + bptr& operator=(bptr&&) noexcept requires std::is_convertible_v; - bptr(bptr&&) noexcept; - bptr& operator=(bptr&&) noexcept; - template Y> bptr(bptr&&) noexcept; - template Y> bptr& operator=(bptr&&) noexcept; + template Y> bptr(bptr&&) noexcept + requires std::is_convertible_v; + template Y> bptr& operator=(bptr&&) noexcept + requires std::is_convertible_v; void reset() noexcept; void destroy() noexcept; @@ -76,7 +89,7 @@ public: bool operator==(const bptr>& other) const noexcept; bool operator==(const bptr>& other) const noexcept; - template requires std::is_convertible_v friend class bptr; + template friend class bptr; template requires (std::is_convertible_v && detail_borrowed_ptr::StaticCastable) diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index c4f19de5..8faa4d4e 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -39,30 +39,31 @@ struct control_block namespace floormat { template -requires std::is_convertible_v template -requires std::is_constructible_v, Ts&&...> +requires (std::is_constructible_v, Ts&&...> && std::is_convertible_v) bptr::bptr(InPlaceInitT, Ts&&... args) noexcept: -bptr{ new std::remove_const_t{ forward(args)... } } -{ -} + bptr{ new std::remove_const_t{ forward(args)... } } +{} template -requires std::is_convertible_v -bptr::bptr(std::nullptr_t) noexcept: blk{nullptr} {} +bptr::bptr(std::nullptr_t) noexcept +requires std::is_convertible_v: + blk{nullptr} +{} template -requires std::is_convertible_v -bptr::bptr() noexcept: bptr{nullptr} {} +bptr::bptr() noexcept +requires std::is_convertible_v: + bptr{nullptr} +{} template -requires std::is_convertible_v -bptr::bptr(T* ptr) noexcept: +bptr::bptr(T* ptr) noexcept +requires std::is_convertible_v: blk{ptr ? new detail_borrowed_ptr::control_block{const_cast*>(ptr), 1} : nullptr} {} template -requires std::is_convertible_v bptr::~bptr() noexcept { if (blk) @@ -70,44 +71,51 @@ bptr::~bptr() noexcept } template -requires std::is_convertible_v -bptr::bptr(const bptr& other) noexcept: bptr{other, nullptr} {} +bptr::bptr(const bptr& other) noexcept +requires std::is_convertible_v: + bptr{other, nullptr} +{} -template +template bptr& bptr::operator=(const bptr& other) noexcept requires std::is_convertible_v -bptr& bptr::operator=(const bptr& other) noexcept { return _copy_assign(other); } +{ return _copy_assign(other); } -template -requires std::is_convertible_v -template Y> -bptr::bptr(const bptr& other) noexcept: bptr{other, nullptr} {} +template template Y> +bptr::bptr(const bptr& other) noexcept +requires std::is_convertible_v: + bptr{other, nullptr} +{} template -requires std::is_convertible_v template Y> bptr& bptr::operator=(const bptr& other) noexcept +requires std::is_convertible_v { return _copy_assign(other); } template +bptr& bptr::operator=(bptr&& other) noexcept requires std::is_convertible_v -bptr& bptr::operator=(bptr&& other) noexcept { return _move_assign(move(other)); } -template -requires std::is_convertible_v -bptr::bptr(bptr&& other) noexcept: bptr{move(other), nullptr} {} +{ return _move_assign(move(other)); } template -requires std::is_convertible_v -template Y> -bptr::bptr(bptr&& other) noexcept: bptr{move(other), nullptr} {} +bptr::bptr(bptr&& other) noexcept +requires std::is_convertible_v: + bptr{move(other), nullptr} +{} + +template template Y> +bptr::bptr(bptr&& other) noexcept +requires std::is_convertible_v: + bptr{move(other), nullptr} +{} template -requires std::is_convertible_v template Y> bptr& bptr::operator=(bptr&& other) noexcept +requires std::is_convertible_v { return _move_assign(move(other)); } template -requires std::is_convertible_v void bptr::reset() noexcept { if (blk) @@ -115,7 +123,6 @@ void bptr::reset() noexcept } template -requires std::is_convertible_v void bptr::destroy() noexcept { if (!blk) @@ -125,12 +132,13 @@ void bptr::destroy() noexcept } template +bptr& bptr::operator=(std::nullptr_t) noexcept requires std::is_convertible_v -bptr& bptr::operator=(std::nullptr_t) noexcept { reset(); return *this; } +{ reset(); return *this; } template -requires std::is_convertible_v template +requires std::is_convertible_v bptr::bptr(const bptr& other, std::nullptr_t) noexcept: blk{other.blk} { @@ -142,7 +150,6 @@ bptr::bptr(const bptr& other, std::nullptr_t) noexcept: } template -requires std::is_convertible_v template bptr& bptr::_copy_assign(const bptr& other) noexcept { @@ -158,8 +165,8 @@ bptr& bptr::_copy_assign(const bptr& other) noexcept } template -requires std::is_convertible_v template +requires std::is_convertible_v bptr::bptr(bptr&& other, std::nullptr_t) noexcept: blk{other.blk} { @@ -167,7 +174,6 @@ bptr::bptr(bptr&& other, std::nullptr_t) noexcept: } template -requires std::is_convertible_v template bptr& bptr::_move_assign(bptr&& other) noexcept { @@ -179,7 +185,6 @@ bptr& bptr::_move_assign(bptr&& other) noexcept } template -requires std::is_convertible_v T* bptr::get() const noexcept { if (blk) [[likely]] @@ -189,7 +194,6 @@ T* bptr::get() const noexcept } template -requires std::is_convertible_v T* bptr::operator->() const noexcept { auto* ret = get(); @@ -198,30 +202,24 @@ T* bptr::operator->() const noexcept } template -requires std::is_convertible_v T& bptr::operator*() const noexcept { return *operator->(); } template -requires std::is_convertible_v bptr::operator bool() const noexcept { return get(); } template -requires std::is_convertible_v bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } template -requires std::is_convertible_v bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } template -requires std::is_convertible_v void bptr::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); } template -requires std::is_convertible_v uint32_t bptr::use_count() const noexcept { if (blk && blk->_ptr) [[likely]] -- cgit v1.2.3