summaryrefslogtreecommitdiffhomepage
path: root/compat/borrowed-ptr-fwd.hpp
blob: b28c6a71405760549ab8622b2c9a91f95af52c0b (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

namespace floormat::detail_borrowed_ptr {

struct control_block_;

template<typename From, typename To>
concept StaticCastable = requires(From* ptr) {
    static_cast<To*>(ptr);
};

} // namespace floormat::detail_borrowed_ptr

namespace floormat {

template<typename T>
class bptr final // NOLINT(*-special-member-functions)
{
    T* ptr; // todo add simple_bptr that doesn't allow casting. should only have the control block member variable.
    detail_borrowed_ptr::control_block_* blk;

public:
    template<typename... Ts>
    requires std::is_constructible_v<T, Ts&&...>
    explicit bptr(InPlaceInitT, Ts&&... args) noexcept;

    constexpr bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions)
    constexpr bptr() noexcept;
    explicit constexpr bptr(NoInitT) noexcept;
    explicit bptr(T* ptr) noexcept;
    ~bptr() noexcept;

    template<typename Y> requires std::is_convertible_v<Y*, T*> bptr(const bptr<Y>&) noexcept;
    template<typename Y> requires std::is_convertible_v<Y*, T*> bptr(bptr<Y>&&) noexcept;
    template<typename Y> requires std::is_convertible_v<Y*, T*> bptr& operator=(const bptr<Y>&) noexcept;
    template<typename Y> requires std::is_convertible_v<Y*, T*> bptr& operator=(bptr<Y>&&) noexcept;

    void swap() noexcept;
    T* get() noexcept;
    const T* get() const noexcept;
    T& operator*() const noexcept;
    T* operator->() const noexcept;
    uint32_t use_count() const noexcept;
    explicit operator bool() const noexcept;

    template<typename U>
    requires detail_borrowed_ptr::StaticCastable<T, U>
    bptr<U> static_pointer_cast() noexcept;
};

} // namespace floormat