summaryrefslogtreecommitdiffhomepage
path: root/compat/borrowed-ptr-fwd.hpp
blob: da91502dbb89475582026a0f638dbc12cd9aad9c (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
#pragma once

namespace floormat::detail_borrowed_ptr { struct control_block_; }

namespace floormat {

template<typename T> class bptr;
template<typename T> bool operator==(const bptr<T>& a, const bptr<T>& b) noexcept;

template<typename T>
class bptr final // NOLINT(*-special-member-functions)
{
    mutable T* casted_ptr;
    detail_borrowed_ptr::control_block_* blk;

    explicit bptr(DirectInitT, T* casted_ptr, detail_borrowed_ptr::control_block_* blk) noexcept;
    //explicit bptr(NoInitT) noexcept;

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

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

    bptr& operator=(std::nullptr_t) 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& operator=(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=(bptr<Y>&&) noexcept;

    friend bool operator==<T>(const bptr<T>& a, const bptr<T>& b) noexcept;
    explicit operator bool() const noexcept;
    void reset() noexcept;
    template<bool MaybeEmpty = true> void destroy() noexcept;
    void swap(bptr& other) noexcept;
    uint32_t use_count() const noexcept;

    T* get() const noexcept;
    T* operator->() const noexcept;
    T& operator*() const noexcept;

    template<typename U> friend class bptr;
    template<typename Tʹ, typename U> friend bptr<U> static_pointer_cast(const bptr<>& p) noexcept;
};

} // namespace floormat