summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-07-15 08:56:21 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-07-15 08:57:45 +0200
commit0c0fe15bdd5fb7f137c6807ba43336f24f6df35b (patch)
tree7cc87418362e936f909b89fd84bd2b000fed0ae3 /compat
parent2d2e0d19cf0fa03ea8c0dc59411205bd4f3cdc7e (diff)
w
Diffstat (limited to 'compat')
-rw-r--r--compat/borrowed-ptr.cpp4
-rw-r--r--compat/borrowed-ptr.hpp50
-rw-r--r--compat/borrowed-ptr.inl96
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<typename From, typename To>
concept DerivedFrom = requires(From* x) {
- !std::is_same_v<From, To>;
std::is_convertible_v<From*, To*>;
};
-} // namespace floormat::detail_borrowed_ptr
+} // namespace floormat::detail_bptr
namespace floormat {
@@ -33,47 +32,30 @@ struct bptr_base
template<typename T>
class bptr final // NOLINT(*-special-member-functions)
{
- detail_borrowed_ptr::control_block* blk;
-
- template<typename Y>
- requires std::is_convertible_v<T*, const bptr_base*>
- bptr(const bptr<Y>& other, std::nullptr_t) noexcept;
-
- template<typename Y>
- requires std::is_convertible_v<T*, const bptr_base*>
- bptr(bptr<Y>&& other, std::nullptr_t) noexcept;
+ detail_bptr::control_block* blk;
+ template<typename Y> bptr(const bptr<Y>& other, std::nullptr_t) noexcept;
+ template<typename Y> bptr(bptr<Y>&& other, std::nullptr_t) noexcept;
template<typename Y> bptr& _copy_assign(const bptr<Y>& other) noexcept;
template<typename Y> bptr& _move_assign(bptr<Y>&& other) noexcept;
public:
template<typename... Ts>
- requires (std::is_constructible_v<std::remove_const_t<T>, Ts&&...> && std::is_convertible_v<T*, const bptr_base*>)
+ requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...>
explicit bptr(InPlaceInitT, Ts&&... args) noexcept;
- explicit bptr(T* ptr) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
- bptr() noexcept requires std::is_convertible_v<T*, const bptr_base*>;
+ explicit bptr(T* ptr) noexcept requires std::is_convertible_v<const T*, const bptr_base*>;
+ bptr() noexcept;
~bptr() noexcept;
- bptr(std::nullptr_t) noexcept requires std::is_convertible_v<T*, const bptr_base*>; // NOLINT(*-explicit-conversions)
- bptr& operator=(std::nullptr_t) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
-
- bptr(const bptr&) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
- bptr& operator=(const bptr&) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
-
- template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr(const bptr<Y>&) noexcept
- requires std::is_convertible_v<T*, const bptr_base*>;
-
- template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr& operator=(const bptr<Y>&) noexcept
- requires std::is_convertible_v<T*, const bptr_base*>;
+ bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions)
+ bptr& operator=(std::nullptr_t) noexcept;
- bptr(bptr&&) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
- bptr& operator=(bptr&&) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
+ template<detail_bptr::DerivedFrom<T> Y> bptr(const bptr<Y>&) noexcept;
+ template<detail_bptr::DerivedFrom<T> Y> bptr& operator=(const bptr<Y>&) noexcept;
- template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr(bptr<Y>&&) noexcept
- requires std::is_convertible_v<T*, const bptr_base*>;
- template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr& operator=(bptr<Y>&&) noexcept
- requires std::is_convertible_v<T*, const bptr_base*>;
+ template<detail_bptr::DerivedFrom<T> Y> bptr(bptr<Y>&&) noexcept;
+ template<detail_bptr::DerivedFrom<T> Y> bptr& operator=(bptr<Y>&&) noexcept;
void reset() noexcept;
void destroy() noexcept;
@@ -91,12 +73,12 @@ public:
template<typename U> friend class bptr;
template<typename To, typename From>
- requires (std::is_convertible_v<To*, const bptr_base*> && detail_borrowed_ptr::StaticCastable<From, To>)
+ requires detail_bptr::StaticCastable<From, To>
friend bptr<To> static_pointer_cast(const bptr<From>& p) noexcept;
};
template<typename To, typename From>
-requires (std::is_convertible_v<To*, const bptr_base*> && detail_borrowed_ptr::StaticCastable<From, To>)
+requires detail_bptr::StaticCastable<From, To>
bptr<To> static_pointer_cast(const bptr<From>& 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<typename T>
template<typename... Ts>
-requires (std::is_constructible_v<std::remove_const_t<T>, Ts&&...> && std::is_convertible_v<T*, const bptr_base*>)
+requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...>
bptr<T>::bptr(InPlaceInitT, Ts&&... args) noexcept:
bptr{ new std::remove_const_t<T>{ forward<Ts...>(args)... } }
{}
-template<typename T>
-bptr<T>::bptr(std::nullptr_t) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
- blk{nullptr}
-{}
+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() noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
- bptr{nullptr}
+template<typename T> bptr<T>::bptr(T* ptr) noexcept requires std::is_convertible_v<const T*, const bptr_base*>:
+ blk{ptr ? new detail_bptr::control_block{const_cast<std::remove_const_t<T>*>(ptr), 1} : nullptr}
{}
-template<typename T>
-bptr<T>::bptr(T* ptr) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
- 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 { if (blk) blk->decrement(blk); }
template<typename T>
-bptr<T>::~bptr() noexcept
-{
- if (blk)
- blk->decrement(blk);
-}
-
-template<typename T>
-bptr<T>::bptr(const bptr& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
- bptr{other, nullptr}
-{}
-
-template<typename T> bptr<T>& bptr<T>::operator=(const bptr& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>
-{ return _copy_assign(other); }
-
-template<typename T> template<detail_borrowed_ptr::DerivedFrom<T> Y>
-bptr<T>::bptr(const bptr<Y>& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
+template<detail_bptr::DerivedFrom<T> Y>
+bptr<T>::bptr(const bptr<Y>& other) noexcept:
bptr{other, nullptr}
{}
template<typename T>
-template<detail_borrowed_ptr::DerivedFrom<T> Y>
+template<detail_bptr::DerivedFrom<T> Y>
bptr<T>& bptr<T>::operator=(const bptr<Y>& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>
{ return _copy_assign(other); }
template<typename T>
-bptr<T>& bptr<T>::operator=(bptr&& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>
-{ return _move_assign(move(other)); }
-
-template<typename T>
-bptr<T>::bptr(bptr&& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
- bptr{move(other), nullptr}
-{}
-
-template<typename T> template<detail_borrowed_ptr::DerivedFrom<T> Y>
-bptr<T>::bptr(bptr<Y>&& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>:
+template<detail_bptr::DerivedFrom<T> Y>
+bptr<T>::bptr(bptr<Y>&& other) noexcept:
bptr{move(other), nullptr}
{}
template<typename T>
-template<detail_borrowed_ptr::DerivedFrom<T> Y>
+template<detail_bptr::DerivedFrom<T> Y>
bptr<T>& bptr<T>::operator=(bptr<Y>&& other) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>
{ return _move_assign(move(other)); }
template<typename T>
@@ -131,14 +92,10 @@ void bptr<T>::destroy() noexcept
blk->_ptr = nullptr;
}
-template<typename T>
-bptr<T>& bptr<T>::operator=(std::nullptr_t) noexcept
-requires std::is_convertible_v<T*, const bptr_base*>
-{ reset(); return *this; }
+template<typename T> bptr<T>& bptr<T>::operator=(std::nullptr_t) noexcept { reset(); return *this; }
template<typename T>
template<typename Y>
-requires std::is_convertible_v<T*, const bptr_base*>
bptr<T>::bptr(const bptr<Y>& other, std::nullptr_t) noexcept:
blk{other.blk}
{
@@ -148,7 +105,6 @@ bptr<T>::bptr(const bptr<Y>& other, std::nullptr_t) noexcept:
template<typename T>
template<typename Y>
-requires std::is_convertible_v<T*, const bptr_base*>
bptr<T>::bptr(bptr<Y>&& other, std::nullptr_t) noexcept:
blk{other.blk}
{
@@ -198,23 +154,11 @@ T* bptr<T>::operator->() const noexcept
return ret;
}
-template<typename T>
-T& bptr<T>::operator*() const noexcept { return *operator->(); }
-
-template<typename T>
-bptr<T>::operator bool() const noexcept { return get(); }
-
-template<typename T>
-bool bptr<T>::operator==(const bptr<const std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); }
-
-template<typename T>
-bool bptr<T>::operator==(const bptr<std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); }
-
-template<typename T>
-void bptr<T>::swap(bptr& other) noexcept
-{
- floormat::swap(blk, other.blk);
-}
+template<typename T> T& bptr<T>::operator*() const noexcept { return *operator->(); }
+template<typename T> bptr<T>::operator bool() const noexcept { return get(); }
+template<typename T> bool bptr<T>::operator==(const bptr<const std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); }
+template<typename T> bool bptr<T>::operator==(const bptr<std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); }
+template<typename T> void bptr<T>::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); }
template<typename T>
uint32_t bptr<T>::use_count() const noexcept