blob: 872902a2699dbde654ad2a117a028e79e98891ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#pragma once
#include "borrowed-ptr-fwd.hpp"
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, typename U>
bptr<U> static_pointer_cast(const bptr<T>& p) noexcept
{
static_assert(detail_borrowed_ptr::StaticCastable<T, U>);
if (auto* blk = p.blk) [[likely]]
{
auto* ptr = static_cast<U*>(p.ptr);
blk->incr();
return bptr<U>{DirectInit, ptr, blk};
}
else
return bptr<U>{nullptr};
}
} // namespace floormat
|