summaryrefslogtreecommitdiffhomepage
path: root/compat/borrowed-ptr.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-04 15:50:13 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-05 03:31:19 +0200
commit5e00350a9373056ca32f9cfb03c2f0e0e4acf385 (patch)
tree4fa885028edf58cbb6bf269c63ae26889c7819e4 /compat/borrowed-ptr.hpp
parentc1ad7d0ead5132520956c8d6ee6a9c6887d38556 (diff)
a w
Diffstat (limited to 'compat/borrowed-ptr.hpp')
-rw-r--r--compat/borrowed-ptr.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp
index 872902a2..d3feee2f 100644
--- a/compat/borrowed-ptr.hpp
+++ b/compat/borrowed-ptr.hpp
@@ -1,11 +1,35 @@
#pragma once
#include "borrowed-ptr-fwd.hpp"
+#include "borrowed-ptr.inl"
+
+#define FM_BPTR_DEBUG
+#ifdef FM_BPTR_DEBUG
+#include "compat/assert.hpp"
+#define fm_bptr_assert(...) fm_debug_assert(__VA_ARGS__)
+#else
+#define fm_bptr_assert(...) void()
+#endif
+
+namespace floormat::detail_borrowed_ptr {
+
+//static_assert(std::is_same_v<T, U> || std::has_virtual_destructor_v<T> && std::has_virtual_destructor_v<T>); // todo! for simple_bptr
+
+template<typename From, typename To>
+concept StaticCastable = requires(From* from) {
+ static_cast<To*>(from);
+};
+
+} // namespace floormat::detail_borrowed_ptr
namespace floormat {
template<typename T> constexpr bptr<T>::bptr(std::nullptr_t) noexcept: ptr{nullptr}, blk{nullptr} {}
template<typename T> constexpr bptr<T>::bptr() noexcept: bptr{nullptr} {}
+template<typename T> constexpr T* bptr<T>::get() const noexcept { return ptr; }
+template<typename T> constexpr T& bptr<T>::operator*() const noexcept { fm_debug_assert(ptr); return *ptr; }
+template<typename T> constexpr T* bptr<T>::operator->() const noexcept { fm_debug_assert(ptr); return ptr; }
+
template<typename T, typename U>
bptr<U> static_pointer_cast(const bptr<T>& p) noexcept
{