throwing_ptr
Smart pointers that throw on dereference if null
unique_ptr.hpp
Go to the documentation of this file.
1 // Copyright Claudio Bantaloukas 2017-2018.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 /** \file unique_ptr.hpp throwing/unique_ptr.hpp
6  * \brief throwing::unique_ptr implementation
7  */
8 
9 #pragma once
10 #include <functional>
11 #include <memory>
12 #include <throwing/null_ptr_exception.hpp>
13 #include <throwing/private/compiler_checks.hpp>
14 
15 namespace throwing {
16 
17 /** \class throwing::unique_ptr throwing/unique_ptr.hpp
18  * \brief unique_ptr that manages a single object
19  *
20  * throwing::unique_ptr is a smart pointer that owns and manages another object
21  * through a pointer and disposes of that object when the unique_ptr goes out of
22  * scope.
23  *
24  * The object is disposed of using the associated deleter when either of the
25  * following happens:
26  * - the managing unique_ptr object is destroyed
27  * - the managing unique_ptr object is assigned another pointer via operator= or
28  * reset().
29  *
30  * The object is disposed of using a potentially user-supplied deleter by
31  * calling get_deleter()(ptr). The default deleter uses the delete operator,
32  * which destroys the object and deallocates the memory.
33  *
34  * A unique_ptr may alternatively own no object, in which case it is called
35  * empty.
36  */
37 template <typename T, typename Deleter = std::default_delete<T>>
38 class unique_ptr {
39 public:
40  /** \brief type of the wrapped std::unique_ptr. */
41  typedef typename std::unique_ptr<T, Deleter> std_unique_ptr_type;
42  /** \brief type of the pointer to the pointed object. */
43  typedef typename std::unique_ptr<T, Deleter>::pointer pointer;
44  /** \brief type of the pointed object. */
45  typedef typename std::unique_ptr<T, Deleter>::element_type element_type;
46  /** \brief type of the deleter. */
47  typedef typename std::unique_ptr<T, Deleter>::deleter_type deleter_type;
48 
49  // allow access to p for other throwing::unique_ptr instantiations
50  template <typename OtherT, typename OtherDeleter> friend class unique_ptr;
51 
52  /** \brief Constructs a unique_ptr that owns nothing.
53  *
54  * Value-initializes the stored pointer and the stored deleter.
55  * Requires that Deleter is DefaultConstructible and that construction does
56  * not throw an exception.
57  */
59 
60  /** \brief Constructs a unique_ptr that owns nothing.
61  *
62  * Value-initializes the stored pointer and the stored deleter.
63  * Requires that Deleter is DefaultConstructible and that construction does
64  * not throw an exception.
65  */
67 
68  /** \brief Constructs a unique_ptr which owns p.
69  *
70  * Initialises the stored pointer with ptr and value-initialises the stored
71  * deleter.
72  *
73  * Requires that Deleter is DefaultConstructible and that construction does
74  * not throw an exception.
75  */
76  explicit unique_ptr(pointer ptr) TSP_NOEXCEPT : p(ptr) {}
77 
78  /** \brief Constructs a std::unique_ptr object which owns p
79  *
80  * Initialises the stored pointer with ptr and initialises the stored
81  * deleter with d1
82  *
83  * Requires that Deleter is nothrow-CopyConstructible
84  *
85  * @todo the current implementation fails for VS2013
86  */
88  typename std::conditional<std::is_reference<Deleter>::value,
89  Deleter, const Deleter &>::type d1)
90  TSP_NOEXCEPT : p(ptr, std::forward<decltype(d1)>(d1)) {}
91 
92  /** \brief Constructs a std::unique_ptr object which owns p
93  *
94  * Initialises the stored pointer with ptr.
95  * Moves d2 into stored_deleter.
96  */
98  typename std::remove_reference<Deleter>::type &&d2) TSP_NOEXCEPT
99  : p(ptr, std::forward<decltype(d2)>(d2)) {}
100 
101  /** \brief Constructs a unique_ptr by transferring ownership from u to
102  * *this.
103  *
104  * If Deleter is not a reference type, requires that it is
105  * nothrow-MoveConstructible (if Deleter is a reference, get_deleter() and
106  * u.get_deleter() after move construction reference the same value)
107  */
109 
110  /** \brief Constructs a unique_ptr by transferring ownership from u to
111  * *this, where u is constructed with a specified deleter (E).
112  *
113  * It depends upon whether E is a reference type, as following:
114  * a) if E is a reference type, this deleter is copy constructed from u's
115  * deleter (requires that this construction does not throw)
116  * b) if E is a non-reference type, this deleter is move constructed from
117  * u's deleter (requires that this construction does not throw)
118  *
119  * This constructor only participates in overload resolution if all of the
120  * following is true:
121  * a) unique_ptr<U, E>::pointer is implicitly convertible to pointer
122  * b) U is not an array type
123  * c) Either Deleter is a reference type and E is the same type as D, or
124  * Deleter is not a reference type and E is implicitly convertible to D
125  */
126  template <class U, class E>
128  : p(std::move(u.get_std_unique_ptr())) {}
129 
130  /** \brief Constructs a unique_ptr by transferring ownership from a
131  * std::unique_ptr u to *this, where u is constructed with a specified
132  * deleter (E).
133  *
134  * It depends upon whether E is a reference type, as following:
135  * a) if E is a reference type, this deleter is copy constructed from u's
136  * deleter (requires that this construction does not throw)
137  * b) if E is a non-reference type, this deleter is move constructed from
138  * u's deleter (requires that this construction does not throw)
139  *
140  * This constructor only participates in overload resolution if all of the
141  * following is true:
142  * a) std::unique_ptr<U, E>::pointer is implicitly convertible to pointer
143  * b) U is not an array type
144  * c) Either Deleter is a reference type and E is the same type as D, or
145  * Deleter is not a reference type and E is implicitly convertible to D
146  */
147  template <class U, class E>
148  unique_ptr(std::unique_ptr<U, E> &&u) TSP_NOEXCEPT : p(std::move(u)) {}
149 
150  /** \brief Destructor
151  * If get() == nullptr there are no effects. Otherwise, the owned object is
152  * destroyed via get_deleter()(get()) on the underlying unique_ptr.
153  *
154  * Requires that get_deleter()(get()) does not throw exceptions.
155  */
156  ~unique_ptr() = default;
157 
158  /** \brief Assignment operator
159  *
160  * Transfers ownership from r to *this as if by calling reset(r.release())
161  * followed by an assignment of get_deleter() from
162  * std::forward<E>(r.get_deleter()).
163  *
164  * If Deleter is not a reference type, requires that it is
165  * nothrow-MoveAssignable.
166  *
167  * If Deleter is a reference type, requires that
168  * std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
169  */
171  p = std::move(r.p);
172  return *this;
173  }
174 
175  /** \brief Assignment operator
176  *
177  * Transfers ownership from r to *this as if by calling reset(r.release())
178  * followed by an assignment of get_deleter() from
179  * std::forward<E>(r.get_deleter()).
180  *
181  * If Deleter is not a reference type, requires that it is
182  * nothrow-MoveAssignable.
183  *
184  * If Deleter is a reference type, requires that
185  * std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
186  *
187  * Only participates in overload resolution if U is not an array type and
188  * unique_ptr<U,E>::pointer is implicitly convertible to pointer and
189  * std::is_assignable<Deleter&, E&&>::value is true (since C++17).
190  */
191  template <class U, class E>
193  p = std::move(r.p);
194  return *this;
195  }
196 
197  /** \brief Assignment from std::unique_ptr operator
198  *
199  * Transfers ownership from a std::unique_ptr r to *this as if by calling
200  * reset(r.release()) followed by an assignment of get_deleter() from
201  * std::forward<E>(r.get_deleter()).
202  *
203  * If Deleter is not a reference type, requires that it is
204  * nothrow-MoveAssignable.
205  *
206  * If Deleter is a reference type, requires that
207  * std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
208  *
209  * Only participates in overload resolution if U is not an array type and
210  * unique_ptr<U,E>::pointer is implicitly convertible to pointer and
211  * std::is_assignable<Deleter&, E&&>::value is true (since C++17).
212  */
213  template <class U, class E>
214  unique_ptr &operator=(std::unique_ptr<U, E> &&r) TSP_NOEXCEPT {
215  p = std::move(r);
216  return *this;
217  }
218 
219  /** \brief Assignment operator
220  *
221  * Effectively the same as calling reset().
222  */
224  p = nullptr;
225  return *this;
226  }
227 
228  /** \brief Releases the ownership of the managed object if any.
229  *
230  * get() returns nullptr after the call.
231  *
232  * \return Pointer to the managed object or nullptr if there was no managed
233  * object, i.e. the value which would be returned by get() before the call.
234  */
236 
237  /** \brief Replaces the managed object.
238  *
239  * Given current_ptr, the pointer that was managed by *this, performs the
240  * following actions, in this order:
241  *
242  * - Saves a copy of the current pointer old_ptr = current_ptr
243  * - Overwrites the current pointer with the argument current_ptr = ptr
244  * - If the old pointer was non-empty, deletes the previously managed object
245  * if(old_ptr != nullptr) get_deleter()(old_ptr).
246  */
248 
249  /** \brief Swaps the managed objects and associated deleters of *this and
250  * another unique_ptr object other.
251  */
252  void swap(unique_ptr &other) TSP_NOEXCEPT { p.swap(other.p); }
253 
254  /** \brief Returns a pointer to the managed object or nullptr if no object
255  * is owned.
256  */
257  pointer get() const TSP_NOEXCEPT { return p.get(); }
258 
259  /** \brief Returns the deleter object which would be used for destruction of
260  * the managed object.
261  */
262  Deleter &get_deleter() TSP_NOEXCEPT { return p.get_deleter(); }
263 
264  /** \brief Returns the deleter object which would be used for destruction of
265  * the managed object.
266  */
267  const Deleter &get_deleter() const TSP_NOEXCEPT { return p.get_deleter(); }
268 
269  /** \brief Checks whether *this owns an object, i.e. whether
270  * get() != nullptr.
271  */
272  explicit operator bool() const TSP_NOEXCEPT { return p.operator bool(); }
273 
274  /** \brief Dereferences the stored pointer.
275  *
276  * \throw null_ptr_exception<T> if the pointer is null
277  */
278  typename std::add_lvalue_reference<T>::type operator*() const {
279  if (nullptr == get())
280  throw null_ptr_exception<T>();
281  return *p;
282  }
283 
284  /** \brief Dereferences the stored pointer.
285  *
286  * \throw null_ptr_exception<T> if the pointer is null
287  */
288  pointer operator->() const {
289  const auto ptr = get();
290  if (nullptr == ptr)
291  throw null_ptr_exception<T>();
292  return ptr;
293  }
294 
295  /** \brief Returns reference to the wrapped std::unique_ptr
296  */
298 
299  /** \brief Returns const reference to the wrapped std::unique_ptr
300  */
302  return p;
303  }
304 
305 private:
307 };
308 
309 /** \brief unique_ptr that manages a dynamically-allocated array of objects
310  *
311  * throwing::unique_ptr is a smart pointer that owns and manages another object
312  * through a pointer and disposes of that object when the unique_ptr goes out of
313  * scope.
314  *
315  * The object is disposed of using the associated deleter when either of the
316  * following happens:
317  * - the managing unique_ptr object is destroyed
318  * - the managing unique_ptr object is assigned another pointer via operator= or
319  * reset().
320  *
321  * The object is disposed of using a potentially user-supplied deleter by
322  * calling get_deleter()(ptr). The default deleter uses the delete operator,
323  * which destroys the object and deallocates the memory.
324  *
325  * A unique_ptr may alternatively own no object, in which case it is called
326  * empty.
327  */
328 template <typename T, typename Deleter> class unique_ptr<T[], Deleter> {
329 public:
330  /** \brief type of the wrapped std::unique_ptr. */
331  typedef typename std::unique_ptr<T[], Deleter> std_unique_ptr_type;
332  /** \brief type of the pointer to the pointed objects. */
333  typedef typename std::unique_ptr<T[], Deleter>::pointer pointer;
334  /** \brief type of the pointed objects. */
335  typedef typename std::unique_ptr<T[], Deleter>::element_type element_type;
336  /** \brief type of the deleter. */
337  typedef typename std::unique_ptr<T[], Deleter>::deleter_type deleter_type;
338 
339  // allow access to p for other throwing::unique_ptr instantiations
340  template <typename OtherT, typename OtherDeleter> friend class unique_ptr;
341 
342  /** \brief Constructs a throwing::unique_ptr that owns nothing.
343  *
344  * Value-initializes the stored pointer and the stored deleter.
345  * Requires that Deleter is DefaultConstructible and that construction does
346  * not throw an exception.
347  */
349 
350  /** \brief Constructs a throwing::unique_ptr that owns nothing.
351  *
352  * Value-initializes the stored pointer and the stored deleter.
353  * Requires that Deleter is DefaultConstructible and that construction does
354  * not throw an exception.
355  */
357 
358  /** \brief Constructs a throwing::unique_ptr which owns p.
359  *
360  * Initialises the stored pointer with ptr and value-initialises the stored
361  * deleter.
362  *
363  * Requires that Deleter is DefaultConstructible and that construction does
364  * not throw an exception.
365  *
366  * This constructor is ill-formed if Deleter is of pointer or reference
367  * type. (until C++17)
368  *
369  * This overload only participates in overload resolution if
370  * std::is_default_constructible<Deleter>::value is true and Deleter is not
371  * a pointer type. The program is ill-formed if this constructor is selected
372  * by class template argument deduction. (since C++17)
373  *
374  * This overload will not participate in overload resolution unless one of
375  * the following is true:
376  * - U is the same type as pointer, or
377  * - U is std::nullptr_t, or
378  * - pointer is the same type as element_type* and U is some pointer type V*
379  * such that V(*)[] is implicitly convertible to element_type(*)[]
380  */
381  template <class U> explicit unique_ptr(U ptr) TSP_NOEXCEPT : p(ptr) {}
382 
383  /** \brief Constructs a throwing::unique_ptr object which owns ptr
384  *
385  * Initialises the stored pointer with ptr and initialises the stored
386  * deleter with d1
387  *
388  * This overload will not participate in overload resolution unless one of
389  * the following is true:
390  * - U is the same type as pointer, or
391  * - U is std::nullptr_t, or
392  * - pointer is the same type as element_type* and U is some pointer type V*
393  * such that V(*)[] is implicitly convertible to element_type(*)[]
394  *
395  * @todo the current implementation fails for VS2013
396  */
397  template <class U>
398  unique_ptr(U ptr,
399  typename std::conditional<std::is_reference<Deleter>::value,
400  Deleter, const Deleter &>::type d1)
401  TSP_NOEXCEPT : p(ptr, std::forward<decltype(d1)>(d1)) {}
402 
403  /** \brief Constructs a throwing::unique_ptr object which owns ptr
404  *
405  * Initialises the stored pointer with ptr.
406  * Moves d2 into stored_deleter.
407  *
408  * This overload will not participate in overload resolution unless one of
409  * the following is true:
410  * - U is the same type as pointer, or
411  * - U is std::nullptr_t, or
412  * - pointer is the same type as element_type* and U is some pointer type V*
413  * such that V(*)[] is implicitly convertible to element_type(*)[]
414  */
415  template <class U>
416  unique_ptr(U ptr,
417  typename std::remove_reference<Deleter>::type &&d2) TSP_NOEXCEPT
418  : p(ptr, std::forward<decltype(d2)>(d2)) {}
419 
420  /** \brief Constructs a unique_ptr by transferring ownership from u to
421  * *this.
422  *
423  * If Deleter is not a reference type, requires that it is
424  * nothrow-MoveConstructible (if Deleter is a reference, get_deleter() and
425  * u.get_deleter() after move construction reference the same value)
426  */
428 
429  /** \brief Constructs a unique_ptr by transferring ownership from u to
430  * *this, where u is constructed with a specified deleter (E).
431  *
432  * It depends upon whether E is a reference type, as following:
433  * a) if E is a reference type, this deleter is copy constructed from u's
434  * deleter (requires that this construction does not throw)
435  * b) if E is a non-reference type, this deleter is move constructed from
436  * u's deleter (requires that this construction does not throw)
437  *
438  * This constructor only participates in overload resolution if all of the
439  * following are true:
440  * a) unique_ptr<U, E>::pointer is implicitly convertible to pointer
441  * b) U is an array type
442  * c) pointer is the same type as element_type*
443  * d) unique_ptr<U,E>::pointer is the same type as
444  * unique_ptr<U,E>::element_type*
445  * e) unique_ptr<U,E>::element_type(*)[] is convertible to element_type(*)[]
446  * f) Either Deleter is a reference type and E is the same type as Deleter,
447  * or Deleter is not a reference type and E is implicitly convertible to
448  * Deleter.
449  */
450  template <class U, class E>
452  : p(std::move(u.get_std_unique_ptr())) {}
453 
454  /** \brief Constructs a unique_ptr by transferring ownership from u to
455  * *this, where u is constructed with a specified deleter (E).
456  *
457  * It depends upon whether E is a reference type, as following:
458  * a) if E is a reference type, this deleter is copy constructed from u's
459  * deleter (requires that this construction does not throw)
460  * b) if E is a non-reference type, this deleter is move constructed from
461  * u's deleter (requires that this construction does not throw)
462  *
463  * This constructor only participates in overload resolution if all of the
464  * following are true:
465  * a) unique_ptr<U, E>::pointer is implicitly convertible to pointer
466  * b) U is an array type
467  * c) pointer is the same type as element_type*
468  * d) unique_ptr<U,E>::pointer is the same type as
469  * unique_ptr<U,E>::element_type*
470  * e) unique_ptr<U,E>::element_type(*)[] is convertible to element_type(*)[]
471  * f) Either Deleter is a reference type and E is the same type as Deleter,
472  * or Deleter is not a reference type and E is implicitly convertible to
473  * Deleter.
474  */
475  template <class U, class E>
476  unique_ptr(std::unique_ptr<U, E> &&u) TSP_NOEXCEPT : p(std::move(u)) {}
477 
478  /** \brief Destructor
479  * If get() == nullptr there are no effects. Otherwise, the owned object is
480  * destroyed via get_deleter()(get()) on the underlying unique_ptr.
481  *
482  * Requires that get_deleter()(get()) does not throw exceptions.
483  */
484  ~unique_ptr() = default;
485 
486  /** \brief Assignment operator
487  *
488  * Transfers ownership from r to *this as if by calling reset(r.release())
489  * followed by an assignment of get_deleter() from
490  * std::forward<E>(r.get_deleter()).
491  *
492  * If Deleter is not a reference type, requires that it is
493  * nothrow-MoveAssignable.
494  *
495  * If Deleter is a reference type, requires that
496  * std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
497  */
499  p = std::move(r.p);
500  return *this;
501  }
502 
503  /** \brief Assignment operator
504  *
505  * Transfers ownership from r to *this as if by calling reset(r.release())
506  * followed by an assignment of get_deleter() from
507  * std::forward<E>(r.get_deleter()).
508  *
509  * If Deleter is not a reference type, requires that it is
510  * nothrow-MoveAssignable.
511  *
512  * If Deleter is a reference type, requires that
513  * std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
514  *
515  * Only participates in overload resolution if all of the following is true:
516  * - U is an array type
517  * - pointer is the same type as element_type*
518  * - unique_ptr<U,E>::pointer is the same type as
519  * unique_ptr<U,E>::element_type*
520  * - unique_ptr<U,E>::element_type(*)[] is convertible to element_type(*)[]
521  * - std::is_assignable<Deleter&, E&&>::value is true
522  */
523  template <class U, class E>
525  p = std::move(r.p);
526  return *this;
527  }
528 
529  /** \brief Assignment from std::unique_ptr operator
530  *
531  * Transfers ownership from r to *this as if by calling reset(r.release())
532  * followed by an assignment of get_deleter() from
533  * std::forward<E>(r.get_deleter()).
534  *
535  * If Deleter is not a reference type, requires that it is
536  * nothrow-MoveAssignable.
537  *
538  * If Deleter is a reference type, requires that
539  * std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
540  *
541  * Only participates in overload resolution if all of the following is true:
542  * - U is an array type
543  * - pointer is the same type as element_type*
544  * - unique_ptr<U,E>::pointer is the same type as
545  * unique_ptr<U,E>::element_type*
546  * - unique_ptr<U,E>::element_type(*)[] is convertible to element_type(*)[]
547  * - std::is_assignable<Deleter&, E&&>::value is true
548  */
549  template <class U, class E>
550  unique_ptr &operator=(std::unique_ptr<U, E> &&r) TSP_NOEXCEPT {
551  p = std::move(r);
552  return *this;
553  }
554 
555  /** \brief Assignment operator
556  *
557  * Effectively the same as calling reset().
558  */
560  p = nullptr;
561  return *this;
562  }
563 
564  /** \brief Releases the ownership of the managed object if any.
565  *
566  * get() returns nullptr after the call.
567  *
568  * \return Pointer to the managed object or nullptr if there was no managed
569  * object, i.e. the value which would be returned by get() before the call.
570  */
572 
573  /** \brief Replaces the managed object.
574  *
575  * Given current_ptr, the pointer that was managed by *this, performs the
576  * following actions, in this order:
577  *
578  * - Saves a copy of the current pointer old_ptr = current_ptr
579  * - Overwrites the current pointer with the argument current_ptr = ptr
580  * - If the old pointer was non-empty, deletes the previously managed object
581  * if(old_ptr != nullptr) get_deleter()(old_ptr).
582  */
584 
585  /** \brief Replaces the managed object.
586  *
587  * Given current_ptr, the pointer that was managed by *this, performs the
588  * following actions, in this order:
589  *
590  * - Saves a copy of the current pointer old_ptr = current_ptr
591  * - Overwrites the current pointer with the argument current_ptr = ptr
592  * - If the old pointer was non-empty, deletes the previously managed object
593  * if(old_ptr != nullptr) get_deleter()(old_ptr).
594  *
595  * Will only participate in overload resolution if either:
596  * - U is the same type as pointer, or
597  * - pointer is the same type as element_type* and U is a pointer type V*
598  * such that V(*)[] is convertible to element_type(*)[].
599  * (available since C++17)
600  */
601  template <class U> void reset(U ptr) TSP_NOEXCEPT { p.reset(ptr); }
602 
603  /** \brief Equivalent to reset(pointer())
604  */
605  void reset(std::nullptr_t ptr = nullptr) TSP_NOEXCEPT { p.reset(ptr); }
606 
607  /** \brief Swaps the managed objects and associated deleters of *this and
608  * another unique_ptr object other.
609  */
610  void swap(unique_ptr &other) TSP_NOEXCEPT { p.swap(other.p); }
611 
612  /** \brief Returns a pointer to the managed object or nullptr if no object
613  * is owned.
614  */
615  pointer get() const TSP_NOEXCEPT { return p.get(); }
616 
617  /** \brief Returns the deleter object which would be used for destruction of
618  * the managed object.
619  */
620  Deleter &get_deleter() TSP_NOEXCEPT { return p.get_deleter(); }
621 
622  /** \brief Returns the deleter object which would be used for destruction of
623  * the managed object.
624  */
625  const Deleter &get_deleter() const TSP_NOEXCEPT { return p.get_deleter(); }
626 
627  /** \brief Checks whether *this owns an object, i.e. whether
628  * get() != nullptr.
629  */
630  explicit operator bool() const TSP_NOEXCEPT { return p.operator bool(); }
631 
632  /** \brief provides access to elements of an array managed by a unique_ptr.
633  *
634  * The parameter i shall be less than the number of elements in the array;
635  * otherwise, the behavior is undefined.
636  *
637  * \throw throwing::null_ptr_exception<element_type> if the unique_ptr is
638  * empty
639  */
640  T &operator[](size_t i) const {
641  if (!p)
643  return p[i];
644  }
645 
646  /** \brief Returns reference to the wrapped std::unique_ptr
647  */
649 
650  /** \brief Returns const reference to the wrapped std::unique_ptr
651  */
653  return p;
654  }
655 
656 private:
657  std::unique_ptr<T[], Deleter> p;
658 };
659 
660 /** \namespace throwing::detail
661  * \brief Helpers for make_unique type resolution, see n3656
662  * \see https://isocpp.org/blog/2013/04/n3656-make-unique-revision-1
663  */
664 namespace detail {
665 /** \brief true for throwing::unique_ptr to single object
666  */
667 template <class T> struct _Unique_if {
669 };
670 
671 /** \brief true for throwing::unique_ptr to arrays of unknown length
672  */
673 template <class T> struct _Unique_if<T[]> {
675 };
676 
677 /** \brief true for throwing::unique_ptr to arrays of known length
678  */
679 template <class T, size_t N> struct _Unique_if<T[N]> {
680  typedef void _Known_bound;
681 };
682 } // namespace detail
683 
684 /** \brief Constructs an object of non-array type T and wraps it in a
685  * throwing::unique_ptr using args as the parameter list for the constructor of
686  * T.
687  *
688  * Equivalent to: unique_ptr<T>(new T(std::forward<Args>(args)...))
689  *
690  * This overload only participates in overload resolution if T is not an array
691  * type.
692  */
693 template <class T, class... Args>
694 typename detail::_Unique_if<T>::_Single_object make_unique(Args &&... args) {
695  return unique_ptr<T>(new T(std::forward<Args>(args)...));
696 }
697 
698 /** \brief Constructs an array of unknown bound T and wraps it in a
699  * throwing::unique_ptr
700  *
701  * Equivalent to: unique_ptr<T>(new typename
702  * std::remove_extent<T>::type[size]())
703  *
704  * This overload only participates in overload resolution if T is an array of
705  * unknown bound.
706  */
707 template <class T>
708 typename detail::_Unique_if<T>::_Unknown_bound make_unique(size_t n) {
709  typedef typename std::remove_extent<T>::type U;
710  return unique_ptr<T>(new U[n]());
711 }
712 
713 /** \brief Construction of arrays of known bound is disallowed.
714  */
715 template <class T, class... Args>
716 typename detail::_Unique_if<T>::_Known_bound make_unique(Args &&...) = delete;
717 
718 /** \brief Compare two unique_ptr objects
719  * \return lhs.get() == rhs.get()
720  */
721 template <class T1, class D1, class T2, class D2>
722 bool operator==(const unique_ptr<T1, D1> &lhs, const unique_ptr<T2, D2> &rhs) {
724 }
725 
726 /** \brief Compare two unique_ptr objects
727  * \return !(lhs.get() == rhs.get())
728  */
729 template <class T1, class D1, class T2, class D2>
730 bool operator!=(const unique_ptr<T1, D1> &lhs, const unique_ptr<T2, D2> &rhs) {
732 }
733 
734 /** \brief Compare two unique_ptr objects
735  * \return std::less<CT>()(lhs.get(), rhs.get()), where CT is
736  * std::common_type<unique_ptr<T1, D1>::pointer, unique_ptr<T2,
737  * D2>::pointer>::type
738  */
739 template <class T1, class D1, class T2, class D2>
740 bool operator<(const unique_ptr<T1, D1> &lhs, const unique_ptr<T2, D2> &rhs) {
742 }
743 
744 /** \brief Compare two unique_ptr objects
745  * \return !(rhs < lhs)
746  */
747 template <class T1, class D1, class T2, class D2>
748 bool operator<=(const unique_ptr<T1, D1> &lhs, const unique_ptr<T2, D2> &rhs) {
750 }
751 
752 /** \brief Compare two unique_ptr objects
753  * \return rhs < lhs
754  */
755 template <class T1, class D1, class T2, class D2>
756 bool operator>(const unique_ptr<T1, D1> &lhs, const unique_ptr<T2, D2> &rhs) {
758 }
759 
760 /** \brief Compare two unique_ptr objects
761  * \return !(lhs < rhs)
762  */
763 template <class T1, class D1, class T2, class D2>
764 bool operator>=(const unique_ptr<T1, D1> &lhs, const unique_ptr<T2, D2> &rhs) {
766 }
767 
768 /** \brief Compare two unique_ptr objects
769  * \return lhs.get() == rhs.get()
770  */
771 template <class T1, class D1, class T2, class D2>
772 bool operator==(const std::unique_ptr<T1, D1> &lhs,
773  const unique_ptr<T2, D2> &rhs) {
774  return lhs == rhs.get_std_unique_ptr();
775 }
776 
777 /** \brief Compare two unique_ptr objects
778  * \return !(lhs.get() == rhs.get())
779  */
780 template <class T1, class D1, class T2, class D2>
781 bool operator!=(const std::unique_ptr<T1, D1> &lhs,
782  const unique_ptr<T2, D2> &rhs) {
783  return lhs != rhs.get_std_unique_ptr();
784 }
785 
786 /** \brief Compare two unique_ptr objects
787  * \return std::less<CT>()(lhs.get(), rhs.get()), where CT is
788  * std::common_type<unique_ptr<T1, D1>::pointer,
789  * unique_ptr<T2,D2>::pointer>::type
790  */
791 template <class T1, class D1, class T2, class D2>
792 bool operator<(const std::unique_ptr<T1, D1> &lhs,
793  const unique_ptr<T2, D2> &rhs) {
794  return lhs < rhs.get_std_unique_ptr();
795 }
796 
797 /** \brief Compare two unique_ptr objects
798  * \return !(rhs < lhs)
799  */
800 template <class T1, class D1, class T2, class D2>
801 bool operator<=(const std::unique_ptr<T1, D1> &lhs,
802  const unique_ptr<T2, D2> &rhs) {
803  return lhs <= rhs.get_std_unique_ptr();
804 }
805 
806 /** \brief Compare two unique_ptr objects
807  * \return rhs < lhs
808  */
809 template <class T1, class D1, class T2, class D2>
810 bool operator>(const std::unique_ptr<T1, D1> &lhs,
811  const unique_ptr<T2, D2> &rhs) {
812  return lhs > rhs.get_std_unique_ptr();
813 }
814 
815 /** \brief Compare two unique_ptr objects
816  * \return !(lhs < rhs)
817  */
818 template <class T1, class D1, class T2, class D2>
819 bool operator>=(const std::unique_ptr<T1, D1> &lhs,
820  const unique_ptr<T2, D2> &rhs) {
821  return lhs >= rhs.get_std_unique_ptr();
822 }
823 
824 /** \brief Compare two unique_ptr objects
825  * \return lhs.get() == rhs.get()
826  */
827 template <class T1, class D1, class T2, class D2>
828 bool operator==(const unique_ptr<T1, D1> &lhs,
829  const std::unique_ptr<T2, D2> &rhs) {
830  return lhs.get_std_unique_ptr() == rhs;
831 }
832 
833 /** \brief Compare two unique_ptr objects
834  * \return !(lhs.get() == rhs.get())
835  */
836 template <class T1, class D1, class T2, class D2>
837 bool operator!=(const unique_ptr<T1, D1> &lhs,
838  const std::unique_ptr<T2, D2> &rhs) {
839  return lhs.get_std_unique_ptr() != rhs;
840 }
841 
842 /** \brief Compare two unique_ptr objects
843  * \return std::less<CT>()(lhs.get(), rhs.get()), where CT is
844  * std::common_type<unique_ptr<T1, D1>::pointer,
845  * unique_ptr<T2,D2>::pointer>::type
846  */
847 template <class T1, class D1, class T2, class D2>
848 bool operator<(const unique_ptr<T1, D1> &lhs,
849  const std::unique_ptr<T2, D2> &rhs) {
850  return lhs.get_std_unique_ptr() < rhs;
851 }
852 
853 /** \brief Compare two unique_ptr objects
854  * \return !(rhs < lhs)
855  */
856 template <class T1, class D1, class T2, class D2>
857 bool operator<=(const unique_ptr<T1, D1> &lhs,
858  const std::unique_ptr<T2, D2> &rhs) {
859  return lhs.get_std_unique_ptr() <= rhs;
860 }
861 
862 /** \brief Compare two unique_ptr objects
863  * \return rhs < lhs
864  */
865 template <class T1, class D1, class T2, class D2>
866 bool operator>(const unique_ptr<T1, D1> &lhs,
867  const std::unique_ptr<T2, D2> &rhs) {
868  return lhs.get_std_unique_ptr() > rhs;
869 }
870 
871 /** \brief Compare two unique_ptr objects
872  * \return !(lhs < rhs)
873  */
874 template <class T1, class D1, class T2, class D2>
875 bool operator>=(const unique_ptr<T1, D1> &lhs,
876  const std::unique_ptr<T2, D2> &rhs) {
877  return lhs.get_std_unique_ptr() >= rhs;
878 }
879 
880 /** \brief Compare a unique_ptr with a null pointer
881  * \return !lhs
882  */
883 template <class T, class D>
884 bool operator==(const unique_ptr<T, D> &lhs, std::nullptr_t rhs) TSP_NOEXCEPT {
885  return lhs.get_std_unique_ptr() == rhs;
886 }
887 
888 /** \brief Compare a unique_ptr with a null pointer
889  * \return !rhs
890  */
891 template <class T, class D>
892 bool operator==(std::nullptr_t lhs, const unique_ptr<T, D> &rhs) TSP_NOEXCEPT {
893  return lhs == rhs.get_std_unique_ptr();
894 }
895 
896 /** \brief Compare a unique_ptr with a null pointer
897  * \return (bool)lhs
898  */
899 template <class T, class D>
900 bool operator!=(const unique_ptr<T, D> &lhs, std::nullptr_t rhs) TSP_NOEXCEPT {
901  return lhs.get_std_unique_ptr() != rhs;
902 }
903 
904 /** \brief Compare a unique_ptr with a null pointer
905  * \return (bool)rhs
906  */
907 template <class T, class D>
908 bool operator!=(std::nullptr_t lhs, const unique_ptr<T, D> &rhs) TSP_NOEXCEPT {
909  return lhs != rhs.get_std_unique_ptr();
910 }
911 
912 /** \brief Compare a unique_ptr with a null pointer
913  * \return std::less<unique_ptr<T,D>::pointer>()(lhs.get(), nullptr)
914  */
915 template <class T, class D>
916 bool operator<(const unique_ptr<T, D> &lhs, std::nullptr_t rhs) {
917  return lhs.get_std_unique_ptr() < rhs;
918 }
919 
920 /** \brief Compare a unique_ptr with a null pointer
921  * \return std::less<unique_ptr<T,D>::pointer>()(nullptr, rhs.get())
922  */
923 template <class T, class D>
924 bool operator<(std::nullptr_t lhs, const unique_ptr<T, D> &rhs) {
925  return lhs < rhs.get_std_unique_ptr();
926 }
927 
928 /** \brief Compare a unique_ptr with a null pointer
929  * \return !(nullptr < lhs)
930  */
931 template <class T, class D>
932 bool operator<=(const unique_ptr<T, D> &lhs, std::nullptr_t rhs) {
933  return lhs.get_std_unique_ptr() <= rhs;
934 }
935 
936 /** \brief Compare a unique_ptr with a null pointer
937  * \return !(rhs < nullptr)
938  */
939 template <class T, class D>
940 bool operator<=(std::nullptr_t lhs, const unique_ptr<T, D> &rhs) {
941  return lhs <= rhs.get_std_unique_ptr();
942 }
943 
944 /** \brief Compare a unique_ptr with a null pointer
945  * \return nullptr < lhs
946  */
947 template <class T, class D>
948 bool operator>(const unique_ptr<T, D> &lhs, std::nullptr_t rhs) {
949  return lhs.get_std_unique_ptr() > rhs;
950 }
951 
952 /** \brief Compare a unique_ptr with a null pointer
953  * \return rhs < nullptr
954  */
955 template <class T, class D>
956 bool operator>(std::nullptr_t lhs, const unique_ptr<T, D> &rhs) {
957  return lhs > rhs.get_std_unique_ptr();
958 }
959 
960 /** \brief Compare a unique_ptr with a null pointer
961  * \return !(lhs < nullptr)
962  */
963 template <class T, class D>
964 bool operator>=(const unique_ptr<T, D> &lhs, std::nullptr_t rhs) {
965  return lhs.get_std_unique_ptr() >= rhs;
966 }
967 
968 /** \brief Compare a unique_ptr with a null pointer
969  * \return !(nullptr < rhs)
970  */
971 template <class T, class D>
972 bool operator>=(std::nullptr_t lhs, const unique_ptr<T, D> &rhs) {
973  return lhs >= rhs.get_std_unique_ptr();
974 }
975 
976 /** \brief Inserts the value of the pointer stored in ptr into the output stream
977  * os
978  *
979  * Equivalent to os << ptr.get().
980  * \return os
981  */
982 template <class CharT, class Traits, class Y, class D>
983 std::basic_ostream<CharT, Traits> &
984 operator<<(std::basic_ostream<CharT, Traits> &os, const unique_ptr<Y, D> &ptr) {
985  os << ptr.get();
986  return os;
987 }
988 
989 /** \brief Specializes the std::swap algorithm for throwing::unique_ptr.
990  *
991  * Swaps the pointers of lhs and rhs.
992  *
993  * Calls lhs.swap(rhs).
994  *
995  * This function does not participate in overload resolution unless
996  * std::is_swappable<D>::value is true. (since C++17)
997  */
998 template <class T>
999 void swap(throwing::unique_ptr<T> &lhs,
1000  throwing::unique_ptr<T> &rhs) TSP_NOEXCEPT {
1002 }
1003 
1004 } // namespace throwing
1005 
1006 namespace std {
1007 
1008 /** \brief Template specialization of std::hash for throwing::unique_ptr<T>
1009  *
1010  * When enabled, (since C++17) for a given throwing::unique_ptr<T, D> p, this
1011  * specialization ensures that std::hash<throwing::unique_ptr<T, D>>()(p) ==
1012  * std::hash<typename throwing::unique_ptr<T, D>::pointer>()(p.get())
1013  *
1014  * The specialization std::hash<throwing::unique_ptr<T,D>> is enabled (see
1015  * std::hash) if std::hash<typename throwing::unique_ptr<T,D>::pointer> is
1016  * enabled, and is disabled otherwise. (since C++17)
1017  */
1018 template <typename Type, typename Deleter>
1019 struct hash<throwing::unique_ptr<Type, Deleter>> {
1020  size_t operator()(const throwing::unique_ptr<Type, Deleter> &x) const {
1021  return std::hash<typename throwing::unique_ptr<
1022  Type, Deleter>::std_unique_ptr_type>()(x.get_std_unique_ptr());
1023  }
1024 };
1025 
1026 } // namespace std
1027 
1028 #include <throwing/private/clear_compiler_checks.hpp>
unique_ptr(U ptr, typename std::remove_reference< Deleter >::type &&d2) TSP_NOEXCEPT
Constructs a throwing::unique_ptr object which owns ptr.
Definition: unique_ptr.hpp:416
bool operator!=(const unique_ptr< T1, D1 > &lhs, const std::unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:837
std::unique_ptr< T, Deleter > std_unique_ptr_type
type of the wrapped std::unique_ptr.
Definition: unique_ptr.hpp:41
TSP_CONSTEXPR unique_ptr(std::nullptr_t) TSP_NOEXCEPT
Constructs a unique_ptr that owns nothing.
Definition: unique_ptr.hpp:66
~unique_ptr()=default
Destructor If get() == nullptr there are no effects. Otherwise, the owned object is destroyed via get...
~unique_ptr()=default
Destructor If get() == nullptr there are no effects. Otherwise, the owned object is destroyed via get...
void reset(pointer ptr=pointer()) TSP_NOEXCEPT
Replaces the managed object.
Definition: unique_ptr.hpp:247
std::unique_ptr< T, Deleter >::pointer pointer
type of the pointer to the pointed object.
Definition: unique_ptr.hpp:43
void reset(std::nullptr_t ptr=nullptr) TSP_NOEXCEPT
Equivalent to reset(pointer())
Definition: unique_ptr.hpp:605
bool operator<=(const unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:748
bool operator<=(const unique_ptr< T, D > &lhs, std::nullptr_t rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:932
#define TSP_CONSTEXPR
unique_ptr & operator=(unique_ptr< U, E > &&r) TSP_NOEXCEPT
Assignment operator.
Definition: unique_ptr.hpp:524
bool operator==(const unique_ptr< T1, D1 > &lhs, const std::unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:828
bool operator>(const std::unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:810
unique_ptr & operator=(std::unique_ptr< U, E > &&r) TSP_NOEXCEPT
Assignment from std::unique_ptr operator.
Definition: unique_ptr.hpp:550
bool operator>=(const std::unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:819
void swap(unique_ptr &other) TSP_NOEXCEPT
Swaps the managed objects and associated deleters of *this and another unique_ptr object other...
Definition: unique_ptr.hpp:252
operator bool() const TSP_NOEXCEPT
Checks whether *this owns an object, i.e. whether get() != nullptr.
Definition: unique_ptr.hpp:272
unique_ptr that manages a single object
Definition: unique_ptr.hpp:38
pointer get() const TSP_NOEXCEPT
Returns a pointer to the managed object or nullptr if no object is owned.
Definition: unique_ptr.hpp:615
true for throwing::unique_ptr to single object
Definition: unique_ptr.hpp:667
TSP_CONSTEXPR unique_ptr() TSP_NOEXCEPT=default
Constructs a throwing::unique_ptr that owns nothing.
std_unique_ptr_type & get_std_unique_ptr() TSP_NOEXCEPT
Returns reference to the wrapped std::unique_ptr.
Definition: unique_ptr.hpp:297
pointer get() const TSP_NOEXCEPT
Returns a pointer to the managed object or nullptr if no object is owned.
Definition: unique_ptr.hpp:257
const Deleter & get_deleter() const TSP_NOEXCEPT
Returns the deleter object which would be used for destruction of the managed object.
Definition: unique_ptr.hpp:625
pointer release() TSP_NOEXCEPT
Releases the ownership of the managed object if any.
Definition: unique_ptr.hpp:235
bool operator<(std::nullptr_t lhs, const unique_ptr< T, D > &rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:924
bool operator>(const unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:756
pointer release() TSP_NOEXCEPT
Releases the ownership of the managed object if any.
Definition: unique_ptr.hpp:571
#define TSP_NOEXCEPT
bool operator<(const unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:740
Deleter & get_deleter() TSP_NOEXCEPT
Returns the deleter object which would be used for destruction of the managed object.
Definition: unique_ptr.hpp:262
void swap(throwing::unique_ptr< T > &lhs, throwing::unique_ptr< T > &rhs) TSP_NOEXCEPT
Specializes the std::swap algorithm for throwing::unique_ptr.
Definition: unique_ptr.hpp:999
std::unique_ptr< T, Deleter >::deleter_type deleter_type
type of the deleter.
Definition: unique_ptr.hpp:47
std::add_lvalue_reference< T >::type operator*() const
Dereferences the stored pointer.
Definition: unique_ptr.hpp:278
detail::_Unique_if< T >::_Known_bound make_unique(Args &&...)=delete
Construction of arrays of known bound is disallowed.
bool operator<(const unique_ptr< T1, D1 > &lhs, const std::unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:848
unique_ptr(std::unique_ptr< U, E > &&u) TSP_NOEXCEPT
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a spec...
Definition: unique_ptr.hpp:476
bool operator==(const unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:722
bool operator<=(std::nullptr_t lhs, const unique_ptr< T, D > &rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:940
bool operator!=(const std::unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:781
unique_ptr(unique_ptr &&u) TSP_NOEXCEPT
Constructs a unique_ptr by transferring ownership from u to *this.
Definition: unique_ptr.hpp:108
unique_ptr & operator=(unique_ptr< U, E > &&r) TSP_NOEXCEPT
Assignment operator.
Definition: unique_ptr.hpp:192
unique_ptr(pointer ptr) TSP_NOEXCEPT
Constructs a unique_ptr which owns p.
Definition: unique_ptr.hpp:76
Implementations of throwing::shared_ptr, throwing::unique_ptr and related.
const Deleter & get_deleter() const TSP_NOEXCEPT
Returns the deleter object which would be used for destruction of the managed object.
Definition: unique_ptr.hpp:267
unique_ptr & operator=(unique_ptr &&r) TSP_NOEXCEPT
Assignment operator.
Definition: unique_ptr.hpp:498
unique_ptr & operator=(std::unique_ptr< U, E > &&r) TSP_NOEXCEPT
Assignment from std::unique_ptr operator.
Definition: unique_ptr.hpp:214
unique_ptr(unique_ptr< U, E > &&u) TSP_NOEXCEPT
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a spec...
Definition: unique_ptr.hpp:451
bool operator==(const std::unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:772
void reset(pointer ptr=pointer()) TSP_NOEXCEPT
Replaces the managed object.
Definition: unique_ptr.hpp:583
bool operator>(const unique_ptr< T1, D1 > &lhs, const std::unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:866
size_t operator()(const throwing::unique_ptr< Type, Deleter > &x) const
unique_ptr & operator=(std::nullptr_t) TSP_NOEXCEPT
Assignment operator.
Definition: unique_ptr.hpp:223
TSP_CONSTEXPR unique_ptr() TSP_NOEXCEPT=default
Constructs a unique_ptr that owns nothing.
unique_ptr(unique_ptr &&u) TSP_NOEXCEPT
Constructs a unique_ptr by transferring ownership from u to *this.
Definition: unique_ptr.hpp:427
operator bool() const TSP_NOEXCEPT
Checks whether *this owns an object, i.e. whether get() != nullptr.
Definition: unique_ptr.hpp:630
std::unique_ptr< T[], Deleter > std_unique_ptr_type
type of the wrapped std::unique_ptr.
Definition: unique_ptr.hpp:331
unique_ptr(U ptr, typename std::conditional< std::is_reference< Deleter >::value, Deleter, const Deleter &>::type d1) TSP_NOEXCEPT
Constructs a throwing::unique_ptr object which owns ptr.
Definition: unique_ptr.hpp:398
throwing::unique_ptr< T > _Single_object
Definition: unique_ptr.hpp:668
detail::_Unique_if< T >::_Unknown_bound make_unique(size_t n)
Constructs an array of unknown bound T and wraps it in a throwing::unique_ptr.
Definition: unique_ptr.hpp:708
bool operator!=(std::nullptr_t lhs, const unique_ptr< T, D > &rhs) TSP_NOEXCEPT
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:908
std::unique_ptr< T, Deleter >::element_type element_type
type of the pointed object.
Definition: unique_ptr.hpp:45
const std_unique_ptr_type & get_std_unique_ptr() const TSP_NOEXCEPT
Returns const reference to the wrapped std::unique_ptr.
Definition: unique_ptr.hpp:301
bool operator>(std::nullptr_t lhs, const unique_ptr< T, D > &rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:956
bool operator==(const unique_ptr< T, D > &lhs, std::nullptr_t rhs) TSP_NOEXCEPT
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:884
const std_unique_ptr_type & get_std_unique_ptr() const TSP_NOEXCEPT
Returns const reference to the wrapped std::unique_ptr.
Definition: unique_ptr.hpp:652
unique_ptr(std::unique_ptr< U, E > &&u) TSP_NOEXCEPT
Constructs a unique_ptr by transferring ownership from a std::unique_ptr u to *this, where u is constructed with a specified deleter (E).
Definition: unique_ptr.hpp:148
unique_ptr(U ptr) TSP_NOEXCEPT
Constructs a throwing::unique_ptr which owns p.
Definition: unique_ptr.hpp:381
unique_ptr(pointer ptr, typename std::remove_reference< Deleter >::type &&d2) TSP_NOEXCEPT
Constructs a std::unique_ptr object which owns p.
Definition: unique_ptr.hpp:97
bool operator!=(const unique_ptr< T, D > &lhs, std::nullptr_t rhs) TSP_NOEXCEPT
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:900
std::unique_ptr< T[], Deleter >::pointer pointer
type of the pointer to the pointed objects.
Definition: unique_ptr.hpp:333
void swap(unique_ptr &other) TSP_NOEXCEPT
Swaps the managed objects and associated deleters of *this and another unique_ptr object other...
Definition: unique_ptr.hpp:610
pointer operator->() const
Dereferences the stored pointer.
Definition: unique_ptr.hpp:288
bool operator>=(const unique_ptr< T1, D1 > &lhs, const std::unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:875
bool operator<=(const std::unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:801
detail::_Unique_if< T >::_Single_object make_unique(Args &&... args)
Constructs an object of non-array type T and wraps it in a throwing::unique_ptr using args as the par...
Definition: unique_ptr.hpp:694
void reset(U ptr) TSP_NOEXCEPT
Replaces the managed object.
Definition: unique_ptr.hpp:601
bool operator==(std::nullptr_t lhs, const unique_ptr< T, D > &rhs) TSP_NOEXCEPT
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:892
std_unique_ptr_type & get_std_unique_ptr() TSP_NOEXCEPT
Returns reference to the wrapped std::unique_ptr.
Definition: unique_ptr.hpp:648
unique_ptr & operator=(unique_ptr &&r) TSP_NOEXCEPT
Assignment operator.
Definition: unique_ptr.hpp:170
bool operator>=(const unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:764
Deleter & get_deleter() TSP_NOEXCEPT
Returns the deleter object which would be used for destruction of the managed object.
Definition: unique_ptr.hpp:620
TSP_CONSTEXPR unique_ptr(std::nullptr_t) TSP_NOEXCEPT
Constructs a throwing::unique_ptr that owns nothing.
Definition: unique_ptr.hpp:356
bool operator>=(std::nullptr_t lhs, const unique_ptr< T, D > &rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:972
bool operator<(const std::unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:792
unique_ptr(pointer ptr, typename std::conditional< std::is_reference< Deleter >::value, Deleter, const Deleter &>::type d1) TSP_NOEXCEPT
Constructs a std::unique_ptr object which owns p.
Definition: unique_ptr.hpp:87
unique_ptr & operator=(std::nullptr_t) TSP_NOEXCEPT
Assignment operator.
Definition: unique_ptr.hpp:559
T & operator[](size_t i) const
provides access to elements of an array managed by a unique_ptr.
Definition: unique_ptr.hpp:640
bool operator>(const unique_ptr< T, D > &lhs, std::nullptr_t rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:948
bool operator<=(const unique_ptr< T1, D1 > &lhs, const std::unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:857
throwing::unique_ptr< T[]> _Unknown_bound
Definition: unique_ptr.hpp:674
bool operator<(const unique_ptr< T, D > &lhs, std::nullptr_t rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:916
bool operator>=(const unique_ptr< T, D > &lhs, std::nullptr_t rhs)
Compare a unique_ptr with a null pointer.
Definition: unique_ptr.hpp:964
bool operator!=(const unique_ptr< T1, D1 > &lhs, const unique_ptr< T2, D2 > &rhs)
Compare two unique_ptr objects.
Definition: unique_ptr.hpp:730
unique_ptr(unique_ptr< U, E > &&u) TSP_NOEXCEPT
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a spec...
Definition: unique_ptr.hpp:127
std::unique_ptr< T[], Deleter >::element_type element_type
type of the pointed objects.
Definition: unique_ptr.hpp:335
std::unique_ptr< T[], Deleter >::deleter_type deleter_type
type of the deleter.
Definition: unique_ptr.hpp:337