diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-14 14:24:43 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-14 14:31:47 +0200 |
commit | 68a0990512df4721d69b630aafccfb3f53ca7b0e (patch) | |
tree | 2a00f8bdf1830f8adca0f9cff60e2106dd296c7e | |
parent | 6f45f8555be7bef45b7c50a95b898ebba7fb9a92 (diff) |
w
-rw-r--r-- | compat/borrowed-ptr.hpp | 18 | ||||
-rw-r--r-- | compat/borrowed-ptr.inl | 4 | ||||
-rw-r--r-- | test/bptr.cpp | 16 |
3 files changed, 26 insertions, 12 deletions
diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 3982b547..146fc334 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -48,15 +48,15 @@ public: bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions) bptr& operator=(std::nullptr_t) noexcept; - 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; - 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; + CORRADE_ALWAYS_INLINE bptr(const bptr&) noexcept; + CORRADE_ALWAYS_INLINE bptr& operator=(const bptr&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> CORRADE_ALWAYS_INLINE bptr(const bptr<Y>&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> CORRADE_ALWAYS_INLINE bptr& operator=(const bptr<Y>&) noexcept; + + CORRADE_ALWAYS_INLINE bptr(bptr&&) noexcept; + CORRADE_ALWAYS_INLINE bptr& operator=(bptr&&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> CORRADE_ALWAYS_INLINE bptr(bptr<Y>&&) noexcept; + template<detail_borrowed_ptr::DerivedFrom<T> Y> CORRADE_ALWAYS_INLINE 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 c2a8b730..68a545d6 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -134,7 +134,6 @@ bptr<T>& bptr<T>::_copy_assign(const bptr<Y>& other) noexcept { if (blk != other.blk) { - CORRADE_ASSUME(this != &other); // todo see if helps if (blk) blk->decrement(blk); blk = other.blk; @@ -187,8 +186,7 @@ template<typename T> bool bptr<T>::operator==(const bptr<std::remove_const_t<T>> template<typename T> void bptr<T>::swap(bptr& other) noexcept { - using floormat::swap; - swap(blk, other.blk); + floormat::swap(blk, other.blk); } template<typename T> uint32_t bptr<T>::use_count() const noexcept diff --git a/test/bptr.cpp b/test/bptr.cpp index 12bd9442..13c8119e 100644 --- a/test/bptr.cpp +++ b/test/bptr.cpp @@ -337,6 +337,8 @@ void test9() void test10() { + static_assert(std::is_same_v<bptr<const Foo>, std::decay_t<decltype( bptr{std::declval<const Foo*>()} )>>); + fm_assert(bptr<Foo>{} == bptr<Foo>{}); fm_assert(bptr<const Foo>{} == bptr<const Foo>{}); fm_assert(bptr<Foo>{} == bptr<const Foo>{}); @@ -349,8 +351,22 @@ void test10() auto p4 = bptr<Foo>{InPlace, 4}; (void)p4; auto p5 = bptr<const Foo>{p4}; (void)p5; + //p4 = p5; fm_assert(p4->x == 4); fm_assert(p5->x == 4); fm_assert(p4 == p5); + p5 = p4; + fm_assert(p5->x == 4); + fm_assert(p4 == p5); + auto p6 = bptr<const Foo>{p5}; (void)p6; + //p4.swap(p5); + p5.swap(p6); + fm_assert(p5 == p6); + p6.destroy(); + fm_assert(!p6); + fm_assert(p5 == p6); + + (void)bptr<const bptr_base>{p6}; + //(void)bptr<bptr_base>{p6}; } } // namespace |