#pragma once #include "borrowed-ptr-fwd.hpp" #include "compat/assert.hpp" 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 bptr static_pointer_cast(const bptr& p) noexcept { // hack to generate better error message if constexpr (detail_borrowed_ptr::StaticCastable) { if (p.blk && p.blk->_ptr) [[likely]] { fm_assert(p.casted_ptr); auto* ret = static_cast(p.casted_ptr); return bptr{DirectInit, ret, p.blk}; } } else { using detail_borrowed_ptr::StaticCastable; // concepts can't be forward-declared so use static_assert static_assert(StaticCastable, "cannot static_cast, classes must be related by inheritance"); } return bptr{nullptr}; } } // namespace floormat