From 5e00350a9373056ca32f9cfb03c2f0e0e4acf385 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 4 May 2024 15:50:13 +0200 Subject: a w --- compat/borrowed-ptr.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'compat/borrowed-ptr.hpp') 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 || std::has_virtual_destructor_v && std::has_virtual_destructor_v); // todo! for simple_bptr + +template +concept StaticCastable = requires(From* from) { + static_cast(from); +}; + +} // namespace floormat::detail_borrowed_ptr namespace floormat { template constexpr bptr::bptr(std::nullptr_t) noexcept: ptr{nullptr}, blk{nullptr} {} template constexpr bptr::bptr() noexcept: bptr{nullptr} {} +template constexpr T* bptr::get() const noexcept { return ptr; } +template constexpr T& bptr::operator*() const noexcept { fm_debug_assert(ptr); return *ptr; } +template constexpr T* bptr::operator->() const noexcept { fm_debug_assert(ptr); return ptr; } + template bptr static_pointer_cast(const bptr& p) noexcept { -- cgit v1.2.3