summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-07-14 18:16:44 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-07-14 18:19:58 +0200
commit277da30e969b54f5f27d2d621fde12bacedaba27 (patch)
tree75d29acb23a3a7068c3767fcc21a25d7d6953454
parentb32c25b283ea9cc5ae21c3d8870f2f856d5f2f0e (diff)
w
-rw-r--r--compat/borrowed-ptr-fwd.hpp13
-rw-r--r--compat/borrowed-ptr.hpp47
-rw-r--r--compat/borrowed-ptr.inl86
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<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-class bptr;
+template<typename T> class bptr;
-template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr(T* ptr) -> bptr<T>;
-
-template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr(const T* ptr) -> bptr<const T>;
+template<typename T> bptr(T* ptr) -> bptr<T>;
+template<typename T> bptr(const T* ptr) -> bptr<const T>;
} // 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<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
class bptr final // NOLINT(*-special-member-functions)
{
detail_borrowed_ptr::control_block* blk;
- template<typename Y> bptr(const bptr<Y>& other, std::nullptr_t) noexcept;
+ template<typename Y>
+ requires std::is_convertible_v<T*, const bptr_base*>
+ 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;
+
+ template<typename Y>
+ requires std::is_convertible_v<T*, const bptr_base*>
+ bptr(bptr<Y>&& other, std::nullptr_t) 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&&...>
+ requires (std::is_constructible_v<std::remove_const_t<T>, Ts&&...> && std::is_convertible_v<T*, const bptr_base*>)
explicit bptr(InPlaceInitT, Ts&&... args) noexcept;
- explicit bptr(T* ptr) noexcept;
- bptr() 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*>;
~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<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(const bptr&) noexcept;
- bptr& operator=(const bptr&) 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 requires std::is_convertible_v<T*, const bptr_base*>;
+ bptr& operator=(bptr&&) noexcept requires std::is_convertible_v<T*, const bptr_base*>;
- bptr(bptr&&) noexcept;
- bptr& operator=(bptr&&) noexcept;
- template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr(bptr<Y>&&) noexcept;
- template<detail_borrowed_ptr::DerivedFrom<T> Y> bptr& operator=(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*>;
void reset() noexcept;
void destroy() noexcept;
@@ -76,7 +89,7 @@ public:
bool operator==(const bptr<const std::remove_const_t<T>>& other) const noexcept;
bool operator==(const bptr<std::remove_const_t<T>>& other) const noexcept;
- template<typename U> requires std::is_convertible_v<U*, const bptr_base*> friend class bptr;
+ 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>)
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<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
template<typename... Ts>
-requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...>
+requires (std::is_constructible_v<std::remove_const_t<T>, Ts&&...> && std::is_convertible_v<T*, const bptr_base*>)
bptr<T>::bptr(InPlaceInitT, Ts&&... args) noexcept:
-bptr{ new std::remove_const_t<T>{ forward<Ts...>(args)... } }
-{
-}
+ bptr{ new std::remove_const_t<T>{ forward<Ts...>(args)... } }
+{}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>::bptr(std::nullptr_t) noexcept: blk{nullptr} {}
+bptr<T>::bptr(std::nullptr_t) noexcept
+requires std::is_convertible_v<T*, const bptr_base*>:
+ blk{nullptr}
+{}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>::bptr() noexcept: bptr{nullptr} {}
+bptr<T>::bptr() noexcept
+requires std::is_convertible_v<T*, const bptr_base*>:
+ bptr{nullptr}
+{}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>::bptr(T* ptr) noexcept:
+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>
-requires std::is_convertible_v<T*, const bptr_base*>
bptr<T>::~bptr() noexcept
{
if (blk)
@@ -70,44 +71,51 @@ bptr<T>::~bptr() noexcept
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>::bptr(const bptr& other) noexcept: bptr{other, nullptr} {}
+bptr<T>::bptr(const bptr& other) noexcept
+requires std::is_convertible_v<T*, const bptr_base*>:
+ bptr{other, nullptr}
+{}
-template<typename T>
+template<typename T> bptr<T>& bptr<T>::operator=(const bptr& other) noexcept
requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>& bptr<T>::operator=(const bptr& other) noexcept { return _copy_assign(other); }
+{ return _copy_assign(other); }
-template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-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<T> Y>
+bptr<T>::bptr(const bptr<Y>& other) noexcept
+requires std::is_convertible_v<T*, const bptr_base*>:
+ bptr{other, nullptr}
+{}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
template<detail_borrowed_ptr::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*>
-bptr<T>& bptr<T>::operator=(bptr&& other) noexcept { return _move_assign(move(other)); }
-template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>::bptr(bptr&& other) noexcept: bptr{move(other), nullptr} {}
+{ return _move_assign(move(other)); }
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
-template<detail_borrowed_ptr::DerivedFrom<T> Y>
-bptr<T>::bptr(bptr<Y>&& other) noexcept: bptr{move(other), nullptr} {}
+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*>:
+ bptr{move(other), nullptr}
+{}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
template<detail_borrowed_ptr::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>
-requires std::is_convertible_v<T*, const bptr_base*>
void bptr<T>::reset() noexcept
{
if (blk)
@@ -115,7 +123,6 @@ void bptr<T>::reset() noexcept
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
void bptr<T>::destroy() noexcept
{
if (!blk)
@@ -125,12 +132,13 @@ void bptr<T>::destroy() noexcept
}
template<typename T>
+bptr<T>& bptr<T>::operator=(std::nullptr_t) noexcept
requires std::is_convertible_v<T*, const bptr_base*>
-bptr<T>& bptr<T>::operator=(std::nullptr_t) noexcept { reset(); return *this; }
+{ reset(); return *this; }
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
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}
{
@@ -142,7 +150,6 @@ bptr<T>::bptr(const bptr<Y>& other, std::nullptr_t) noexcept:
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
template<typename Y>
bptr<T>& bptr<T>::_copy_assign(const bptr<Y>& other) noexcept
{
@@ -158,8 +165,8 @@ bptr<T>& bptr<T>::_copy_assign(const bptr<Y>& other) noexcept
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
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}
{
@@ -167,7 +174,6 @@ bptr<T>::bptr(bptr<Y>&& other, std::nullptr_t) noexcept:
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
template<typename Y>
bptr<T>& bptr<T>::_move_assign(bptr<Y>&& other) noexcept
{
@@ -179,7 +185,6 @@ bptr<T>& bptr<T>::_move_assign(bptr<Y>&& other) noexcept
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
T* bptr<T>::get() const noexcept
{
if (blk) [[likely]]
@@ -189,7 +194,6 @@ T* bptr<T>::get() const noexcept
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
T* bptr<T>::operator->() const noexcept
{
auto* ret = get();
@@ -198,30 +202,24 @@ T* bptr<T>::operator->() const noexcept
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
T& bptr<T>::operator*() const noexcept { return *operator->(); }
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
bptr<T>::operator bool() const noexcept { return get(); }
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
bool bptr<T>::operator==(const bptr<const std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); }
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
bool bptr<T>::operator==(const bptr<std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); }
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
void bptr<T>::swap(bptr& other) noexcept
{
floormat::swap(blk, other.blk);
}
template<typename T>
-requires std::is_convertible_v<T*, const bptr_base*>
uint32_t bptr<T>::use_count() const noexcept
{
if (blk && blk->_ptr) [[likely]]