From 0c0fe15bdd5fb7f137c6807ba43336f24f6df35b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Jul 2024 08:56:21 +0200 Subject: w --- compat/borrowed-ptr.cpp | 4 +-- compat/borrowed-ptr.hpp | 50 +++++++++----------------- compat/borrowed-ptr.inl | 96 +++++++++++-------------------------------------- 3 files changed, 38 insertions(+), 112 deletions(-) diff --git a/compat/borrowed-ptr.cpp b/compat/borrowed-ptr.cpp index da5c6a72..ab96f94e 100644 --- a/compat/borrowed-ptr.cpp +++ b/compat/borrowed-ptr.cpp @@ -1,7 +1,7 @@ #include "borrowed-ptr.inl" #include "compat/assert.hpp" -namespace floormat::detail_borrowed_ptr { +namespace floormat::detail_bptr { #ifdef __clang__ #pragma clang diagnostic push @@ -34,7 +34,7 @@ void control_block::decrement(control_block*& blk) noexcept #pragma warning(pop) #endif -} // namespace floormat::detail_borrowed_ptr +} // namespace floormat::detail_bptr namespace floormat { diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 6b1dcdf4..28d35b8f 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -1,7 +1,7 @@ #pragma once #include "borrowed-ptr-fwd.hpp" -namespace floormat::detail_borrowed_ptr { +namespace floormat::detail_bptr { struct control_block; @@ -12,11 +12,10 @@ concept StaticCastable = requires(From* from) { template concept DerivedFrom = requires(From* x) { - !std::is_same_v; std::is_convertible_v; }; -} // namespace floormat::detail_borrowed_ptr +} // namespace floormat::detail_bptr namespace floormat { @@ -33,47 +32,30 @@ struct bptr_base template class bptr final // NOLINT(*-special-member-functions) { - detail_borrowed_ptr::control_block* blk; - - template - requires std::is_convertible_v - bptr(const bptr& other, std::nullptr_t) noexcept; - - template - requires std::is_convertible_v - bptr(bptr&& other, std::nullptr_t) noexcept; + detail_bptr::control_block* blk; + template bptr(const bptr& other, std::nullptr_t) noexcept; + template bptr(bptr&& other, std::nullptr_t) noexcept; template bptr& _copy_assign(const bptr& other) noexcept; template bptr& _move_assign(bptr&& other) noexcept; public: template - requires (std::is_constructible_v, Ts&&...> && std::is_convertible_v) + requires std::is_constructible_v, Ts&&...> explicit bptr(InPlaceInitT, Ts&&... args) noexcept; - explicit bptr(T* ptr) noexcept requires std::is_convertible_v; - bptr() noexcept requires std::is_convertible_v; + explicit bptr(T* ptr) noexcept requires std::is_convertible_v; + bptr() noexcept; ~bptr() 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(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions) + bptr& operator=(std::nullptr_t) noexcept; - bptr(bptr&&) noexcept requires std::is_convertible_v; - bptr& operator=(bptr&&) noexcept requires std::is_convertible_v; + template Y> bptr(const bptr&) noexcept; + template Y> bptr& operator=(const bptr&) noexcept; - template Y> bptr(bptr&&) noexcept - requires std::is_convertible_v; - template Y> bptr& operator=(bptr&&) noexcept - requires std::is_convertible_v; + template Y> bptr(bptr&&) noexcept; + template Y> bptr& operator=(bptr&&) noexcept; void reset() noexcept; void destroy() noexcept; @@ -91,12 +73,12 @@ public: template friend class bptr; template - requires (std::is_convertible_v && detail_borrowed_ptr::StaticCastable) + requires detail_bptr::StaticCastable friend bptr static_pointer_cast(const bptr& p) noexcept; }; template -requires (std::is_convertible_v && detail_borrowed_ptr::StaticCastable) +requires detail_bptr::StaticCastable bptr static_pointer_cast(const bptr& p) noexcept { if (p.blk && p.blk->_ptr) [[likely]] diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index c81f1ca0..7260d7ed 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -17,7 +17,7 @@ #pragma GCC diagnostic ignored "-Wunused-function" #endif -namespace floormat::detail_borrowed_ptr { +namespace floormat::detail_bptr { #ifdef __GNUG__ #pragma GCC diagnostic push @@ -34,85 +34,46 @@ struct control_block #endif -} // namespace floormat::detail_borrowed_ptr +} // namespace floormat::detail_bptr namespace floormat { template template -requires (std::is_constructible_v, Ts&&...> && std::is_convertible_v) +requires std::is_constructible_v, Ts&&...> bptr::bptr(InPlaceInitT, Ts&&... args) noexcept: bptr{ new std::remove_const_t{ forward(args)... } } {} -template -bptr::bptr(std::nullptr_t) noexcept -requires std::is_convertible_v: - blk{nullptr} -{} +template bptr::bptr(std::nullptr_t) noexcept: blk{nullptr} {} +template bptr::bptr() noexcept: bptr{nullptr} {} -template -bptr::bptr() noexcept -requires std::is_convertible_v: - bptr{nullptr} +template bptr::bptr(T* ptr) noexcept requires std::is_convertible_v: + blk{ptr ? new detail_bptr::control_block{const_cast*>(ptr), 1} : nullptr} {} -template -bptr::bptr(T* ptr) noexcept -requires std::is_convertible_v: - blk{ptr ? new detail_borrowed_ptr::control_block{const_cast*>(ptr), 1} : nullptr} -{} +template bptr::~bptr() noexcept { if (blk) blk->decrement(blk); } template -bptr::~bptr() noexcept -{ - if (blk) - blk->decrement(blk); -} - -template -bptr::bptr(const bptr& other) noexcept -requires std::is_convertible_v: - bptr{other, nullptr} -{} - -template bptr& bptr::operator=(const bptr& other) noexcept -requires std::is_convertible_v -{ return _copy_assign(other); } - -template template Y> -bptr::bptr(const bptr& other) noexcept -requires std::is_convertible_v: +template Y> +bptr::bptr(const bptr& other) noexcept: bptr{other, nullptr} {} template -template Y> +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 -{ return _move_assign(move(other)); } - -template -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: +template Y> +bptr::bptr(bptr&& other) noexcept: bptr{move(other), nullptr} {} template -template Y> +template Y> bptr& bptr::operator=(bptr&& other) noexcept -requires std::is_convertible_v { return _move_assign(move(other)); } template @@ -131,14 +92,10 @@ void bptr::destroy() noexcept blk->_ptr = nullptr; } -template -bptr& bptr::operator=(std::nullptr_t) noexcept -requires std::is_convertible_v -{ reset(); return *this; } +template bptr& bptr::operator=(std::nullptr_t) noexcept { reset(); return *this; } template template -requires std::is_convertible_v bptr::bptr(const bptr& other, std::nullptr_t) noexcept: blk{other.blk} { @@ -148,7 +105,6 @@ bptr::bptr(const bptr& other, std::nullptr_t) noexcept: template template -requires std::is_convertible_v bptr::bptr(bptr&& other, std::nullptr_t) noexcept: blk{other.blk} { @@ -198,23 +154,11 @@ T* bptr::operator->() const noexcept return ret; } -template -T& bptr::operator*() const noexcept { return *operator->(); } - -template -bptr::operator bool() const noexcept { return get(); } - -template -bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } - -template -bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } - -template -void bptr::swap(bptr& other) noexcept -{ - floormat::swap(blk, other.blk); -} +template T& bptr::operator*() const noexcept { return *operator->(); } +template bptr::operator bool() const noexcept { return get(); } +template bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } +template bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } +template void bptr::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); } template uint32_t bptr::use_count() const noexcept -- cgit v1.2.3