13 template <
typename OBJECT_TYPE>
18 template <
typename OBJECT_TYPE>
22 template <
typename PRINTABLE>
33 template <
typename OBJECT_TYPE>
34 using deleter_t = void (*)(Owned<OBJECT_TYPE>);
36 template <
typename OBJECT_TYPE>
37 void no_op_deleter(Owned<OBJECT_TYPE>) {}
39 template <
typename OBJECT_TYPE>
40 void c_heap_deleter(Owned<OBJECT_TYPE> o)
47 deleter_t<OBJECT_TYPE> Deleter_Fn = &c_heap_deleter,
48 bool Delete_Null =
false
53 using object_type = OBJECT_TYPE;
54 using owned_pointer = Owned<object_type>;
55 using borrowed_pointer = Borrowed<object_type>;
56 using deleter_fn_type = deleter_t<object_type>;
58 static constexpr deleter_fn_type deleter_fn = Deleter_Fn;
59 static constexpr
bool delete_null = Delete_Null;
64 explicit delete_ptr(owned_pointer ptr) noexcept
70 delete_ptr(delete_ptr
const&) =
delete;
71 delete_ptr& operator=(delete_ptr
const&) =
delete;
73 delete_ptr(delete_ptr&& that) noexcept
74 : ptr_(that.release()) { }
76 delete_ptr& operator=(delete_ptr&& that) noexcept
79 ptr_ = that.release();
83 delete_ptr& operator=(owned_pointer that) noexcept
85 return *
this = delete_ptr(that);
93 owned_pointer release() noexcept
95 return std::exchange(ptr_,
nullptr);
98 borrowed_pointer get() const noexcept
108 borrowed_pointer operator->() const noexcept
113 explicit operator bool() const noexcept
115 return ptr_ !=
nullptr;
121 return {release(), deleter_fn};
124 friend void swap(delete_ptr& a, delete_ptr& b) noexcept
130 void delete_it_() noexcept
132 if (delete_null || ptr_)
140 typename OBJECT_TYPE,
141 deleter_t<OBJECT_TYPE> Deleter_Fn
143 bool operator==(delete_ptr<OBJECT_TYPE, Deleter_Fn>
const& a,
144 delete_ptr<OBJECT_TYPE, Deleter_Fn>
const& b)
146 return a.get() == b.get();
150 typename OBJECT_TYPE,
151 deleter_t<OBJECT_TYPE> Deleter_Fn
153 bool operator!=(delete_ptr<OBJECT_TYPE, Deleter_Fn>
const& a,
154 delete_ptr<OBJECT_TYPE, Deleter_Fn>
const& b)
159 template <
typename OBJECT_TYPE>
163 using value = OBJECT_TYPE;
164 using reference = OBJECT_TYPE&;
165 using pointer = OBJECT_TYPE*;
170 bool is_forced()
const
172 return ptr_ !=
nullptr;
181 pointer operator->()
const
192 ptr_.
reset(
new value);
198 template <
typename FROM_TYPE,
typename TO_TYPE = FROM_TYPE>
199 constexpr
bool is_nothrow_convertible()
202 return noexcept(TO_TYPE(t));
206 template <
typename EQ_TYPE>
207 constexpr
bool is_nothrow_comparable()
210 return noexcept(t == t) && noexcept(t != t);
215 template <
typename ARITH_LEFT,
typename ARITH_RIGHT = ARITH_LEFT>
216 constexpr
bool has_nothrow_arithmetic()
220 return noexcept(t + u) && noexcept(t - u) && noexcept(t * u);
225 template <
typename DIVIDEND,
typename DIVISOR = DIVIDEND>
226 constexpr
bool has_nothrow_division()
230 return noexcept(t / u);
238 static constexpr
char const* value =
"?";
241 template <
typename TYPE>
242 char const* name_of_type()
244 return Name_of_type<TYPE>::value;
247 #define Specialize_name_of_type(Type) \
249 struct Name_of_type<Type> \
250 { static constexpr char const* value = #Type; };
252 Specialize_name_of_type(
char)
253 Specialize_name_of_type(
signed char)
254 Specialize_name_of_type(
unsigned char)
255 Specialize_name_of_type(
short)
256 Specialize_name_of_type(
unsigned short)
257 Specialize_name_of_type(
int)
258 Specialize_name_of_type(
unsigned)
259 Specialize_name_of_type(
long)
260 Specialize_name_of_type(
unsigned long)
261 Specialize_name_of_type(
float)
262 Specialize_name_of_type(
double)
264 #undef Specialize_name_of_type