5#ifndef QUNIQUEHANDLE_P_H
6#define QUNIQUEHANDLE_P_H
19#include <QtCore/qtconfigmacros.h>
20#include <QtCore/qassert.h>
21#include <QtCore/qcompare.h>
22#include <QtCore/qfunctionaltools_impl.h>
23#include <QtCore/qswap.h>
24#include <QtCore/qtclasshelpermacros.h>
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
151template <
typename HandleTraits>
158 if (handle != HandleTraits::invalidValue()) {
159 const bool success = HandleTraits::close(handle);
167template <
typename HandleTraits,
typename Deleter = QtUniqueHandleTraits::DefaultDeleter<HandleTraits>>
172 template <
typename D>
177 static_assert(
std::is_nothrow_default_constructible_v<
Type>);
178 static_assert(
std::is_nothrow_constructible_v<
Type>);
179 static_assert(
std::is_nothrow_copy_constructible_v<
Type>);
180 static_assert(
std::is_nothrow_move_constructible_v<
Type>);
181 static_assert(
std::is_nothrow_copy_assignable_v<
Type>);
182 static_assert(
std::is_nothrow_move_assignable_v<
Type>);
183 static_assert(
std::is_nothrow_destructible_v<
Type>);
184 static_assert(
std::is_nothrow_copy_constructible_v<Deleter>);
185 static_assert(
std::is_nothrow_move_constructible_v<Deleter>);
186 static_assert(
std::is_nothrow_copy_assignable_v<Deleter>);
187 static_assert(
std::is_nothrow_move_assignable_v<Deleter>);
188 static_assert(
std::is_nothrow_destructible_v<Deleter>);
189 static_assert(
noexcept(
std::declval<
Type>() ==
std::declval<
Type>()));
190 static_assert(
noexcept(
std::declval<
Type>() !=
std::declval<
Type>()));
191 static_assert(
noexcept(
std::declval<
Type>() <
std::declval<
Type>()));
192 static_assert(
noexcept(
std::declval<
Type>() <=
std::declval<
Type>()));
193 static_assert(
noexcept(
std::declval<
Type>() >
std::declval<
Type>()));
194 static_assert(
noexcept(
std::declval<
Type>() >=
std::declval<
Type>()));
196 template <if_default_constructible<Deleter> =
true>
200 template <if_default_constructible<Deleter> =
true>
225 qSwap(m_handle, other.m_handle);
226 qSwap(deleter(), other.deleter());
237 return m_handle != HandleTraits::invalidValue();
240 [[nodiscard]]
explicit operator bool()
const noexcept
252 return Storage::object();
255 [[nodiscard]]
const Deleter&
deleter()
const noexcept
257 return Storage::object();
260 void reset(
const Type& handle = HandleTraits::invalidValue())
noexcept
262 if (handle == m_handle)
271 return std::exchange(m_handle, HandleTraits::invalidValue());
287 m_handle = HandleTraits::invalidValue();
299 if constexpr (
std::is_pointer_v<
Type>)
300 return qCompareThreeWay(Qt::totally_ordered_wrapper{ lhs.get() },
301 Qt::totally_ordered_wrapper{ rhs.get() });
313template <
typename Trait,
typename Deleter>
Type get() const noexcept
operator bool() const noexcept
friend Qt::strong_ordering compareThreeWay(const QUniqueHandle &lhs, const QUniqueHandle &rhs) noexcept
void swap(QUniqueHandle &other) noexcept
friend bool comparesEqual(const QUniqueHandle &lhs, const QUniqueHandle &rhs) noexcept
QUniqueHandle(QUniqueHandle &&other) noexcept
bool isValid() const noexcept
const Deleter & deleter() const noexcept
~QUniqueHandle() noexcept
QUniqueHandle(const Type &handle, const Deleter &deleter) noexcept
void reset(const Type &handle=HandleTraits::invalidValue()) noexcept
QUniqueHandle(const Type &handle, Deleter &&deleter) noexcept
QUniqueHandle & operator=(const QUniqueHandle &)=delete
Type * operator&() noexcept
Deleter & deleter() noexcept
QUniqueHandle(const Type &handle) noexcept
typename HandleTraits::Type Type
void swap(QUniqueHandle< Trait, Deleter > &lhs, QUniqueHandle< Trait, Deleter > &rhs) noexcept
void operator()(Type handle) const noexcept
typename HandleTraits::Type Type