blob: b181bc9da0b19ebae3b08742e1b1a3401e10a9af [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MEMORY
12#define _LIBCPP_MEMORY
13
14/*
15 memory synopsis
16
17namespace std
18{
19
20struct allocator_arg_t { };
21constexpr allocator_arg_t allocator_arg = allocator_arg_t();
22
23template <class T, class Alloc> struct uses_allocator;
24
25template <class Ptr>
26struct pointer_traits
27{
28 typedef Ptr pointer;
29 typedef <details> element_type;
30 typedef <details> difference_type;
Howard Hinnant324bb032010-08-22 00:02:43 +000031
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032 template <class U> using rebind = <details>;
Howard Hinnant324bb032010-08-22 00:02:43 +000033
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034 static pointer pointer_to(<details>);
35};
36
Howard Hinnant1694d232011-05-28 14:41:13 +000037template <class T>
38struct pointer_traits<T*>
39{
40 typedef T* pointer;
41 typedef T element_type;
42 typedef ptrdiff_t difference_type;
43
44 template <class U> using rebind = U*;
45
46 static pointer pointer_to(<details>) noexcept;
47};
48
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049template <class Alloc>
50struct allocator_traits
51{
52 typedef Alloc allocator_type;
53 typedef typename allocator_type::value_type
54 value_type;
55
56 typedef Alloc::pointer | value_type* pointer;
57 typedef Alloc::const_pointer
58 | pointer_traits<pointer>::rebind<const value_type>
59 const_pointer;
60 typedef Alloc::void_pointer
61 | pointer_traits<pointer>::rebind<void>
62 void_pointer;
63 typedef Alloc::const_void_pointer
64 | pointer_traits<pointer>::rebind<const void>
65 const_void_pointer;
66 typedef Alloc::difference_type
Howard Hinnant47761072010-11-18 01:40:00 +000067 | pointer_traits<pointer>::difference_type
68 difference_type;
69 typedef Alloc::size_type
70 | make_unsigned<difference_type>::type
71 size_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072 typedef Alloc::propagate_on_container_copy_assignment
73 | false_type propagate_on_container_copy_assignment;
74 typedef Alloc::propagate_on_container_move_assignment
75 | false_type propagate_on_container_move_assignment;
76 typedef Alloc::propagate_on_container_swap
77 | false_type propagate_on_container_swap;
78
79 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
80 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
81
82 static pointer allocate(allocator_type& a, size_type n);
83 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
84
Howard Hinnant1694d232011-05-28 14:41:13 +000085 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086
87 template <class T, class... Args>
88 static void construct(allocator_type& a, T* p, Args&&... args);
89
90 template <class T>
91 static void destroy(allocator_type& a, T* p);
92
93 static size_type max_size(const allocator_type& a);
94
95 static allocator_type
96 select_on_container_copy_construction(const allocator_type& a);
97};
98
99template <>
100class allocator<void>
101{
102public:
103 typedef void* pointer;
104 typedef const void* const_pointer;
105 typedef void value_type;
106
107 template <class _Up> struct rebind {typedef allocator<_Up> other;};
108};
109
110template <class T>
111class allocator
112{
113public:
114 typedef size_t size_type;
115 typedef ptrdiff_t difference_type;
116 typedef T* pointer;
117 typedef const T* const_pointer;
118 typedef typename add_lvalue_reference<T>::type reference;
119 typedef typename add_lvalue_reference<const T>::type const_reference;
120 typedef T value_type;
121
122 template <class U> struct rebind {typedef allocator<U> other;};
123
Howard Hinnant1694d232011-05-28 14:41:13 +0000124 allocator() noexcept;
125 allocator(const allocator&) noexcept;
126 template <class U> allocator(const allocator<U>&) noexcept;
127 ~allocator();
128 pointer address(reference x) const noexcept;
129 const_pointer address(const_reference x) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant1694d232011-05-28 14:41:13 +0000131 void deallocate(pointer p, size_type n) noexcept;
132 size_type max_size() const noexcept;
133 template<class U, class... Args>
134 void construct(U* p, Args&&... args);
135 template <class U>
136 void destroy(U* p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137};
138
139template <class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000140bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141
142template <class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000143bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
145template <class OutputIterator, class T>
146class raw_storage_iterator
147 : public iterator<output_iterator_tag,
148 T, // purposefully not C++03
149 ptrdiff_t, // purposefully not C++03
150 T*, // purposefully not C++03
151 raw_storage_iterator&> // purposefully not C++03
152{
153public:
154 explicit raw_storage_iterator(OutputIterator x);
155 raw_storage_iterator& operator*();
156 raw_storage_iterator& operator=(const T& element);
157 raw_storage_iterator& operator++();
158 raw_storage_iterator operator++(int);
159};
160
Howard Hinnant1694d232011-05-28 14:41:13 +0000161template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
162template <class T> void return_temporary_buffer(T* p) noexcept;
163
164template <class T> T* addressof(T& r) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000165
166template <class InputIterator, class ForwardIterator>
167ForwardIterator
168uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
169
Howard Hinnant1694d232011-05-28 14:41:13 +0000170template <class InputIterator, class Size, class ForwardIterator>
171ForwardIterator
172uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
173
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000174template <class ForwardIterator, class T>
175void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
176
177template <class ForwardIterator, class Size, class T>
Howard Hinnant2f6a6272010-11-18 16:13:03 +0000178ForwardIterator
179uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180
181template <class Y> struct auto_ptr_ref {};
182
183template<class X>
184class auto_ptr
185{
186public:
187 typedef X element_type;
188
189 explicit auto_ptr(X* p =0) throw();
190 auto_ptr(auto_ptr&) throw();
191 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
192 auto_ptr& operator=(auto_ptr&) throw();
193 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
194 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
195 ~auto_ptr() throw();
196
197 typename add_lvalue_reference<X>::type operator*() const throw();
198 X* operator->() const throw();
199 X* get() const throw();
200 X* release() throw();
201 void reset(X* p =0) throw();
202
203 auto_ptr(auto_ptr_ref<X>) throw();
204 template<class Y> operator auto_ptr_ref<Y>() throw();
205 template<class Y> operator auto_ptr<Y>() throw();
206};
207
Howard Hinnante92c3d72010-08-19 18:39:17 +0000208template <class T>
209struct default_delete
210{
Howard Hinnant1694d232011-05-28 14:41:13 +0000211 constexpr default_delete() noexcept = default;
212 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000213
Howard Hinnant1694d232011-05-28 14:41:13 +0000214 void operator()(T*) const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000215};
216
217template <class T>
218struct default_delete<T[]>
219{
Howard Hinnant1694d232011-05-28 14:41:13 +0000220 constexpr default_delete() noexcept = default;
221 void operator()(T*) const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000222 template <class U> void operator()(U*) const = delete;
223};
224
Howard Hinnante92c3d72010-08-19 18:39:17 +0000225template <class T, class D = default_delete<T>>
226class unique_ptr
227{
228public:
229 typedef see below pointer;
230 typedef T element_type;
231 typedef D deleter_type;
232
233 // constructors
Howard Hinnant1694d232011-05-28 14:41:13 +0000234 constexpr unique_ptr() noexcept;
235 explicit unique_ptr(pointer p) noexcept;
236 unique_ptr(pointer p, see below d1) noexcept;
237 unique_ptr(pointer p, see below d2) noexcept;
238 unique_ptr(unique_ptr&& u) noexcept;
239 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnante92c3d72010-08-19 18:39:17 +0000240 template <class U, class E>
Howard Hinnant1694d232011-05-28 14:41:13 +0000241 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000242 template <class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000243 unique_ptr(auto_ptr<U>&& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000244
245 // destructor
246 ~unique_ptr();
247
248 // assignment
Howard Hinnant1694d232011-05-28 14:41:13 +0000249 unique_ptr& operator=(unique_ptr&& u) noexcept;
250 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
251 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000252
253 // observers
254 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant1694d232011-05-28 14:41:13 +0000255 pointer operator->() const noexcept;
256 pointer get() const noexcept;
257 deleter_type& get_deleter() noexcept;
258 const deleter_type& get_deleter() const noexcept;
259 explicit operator bool() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000260
261 // modifiers
Howard Hinnant1694d232011-05-28 14:41:13 +0000262 pointer release() noexcept;
263 void reset(pointer p = pointer()) noexcept;
264 void swap(unique_ptr& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000265};
266
267template <class T, class D>
268class unique_ptr<T[], D>
269{
270public:
271 typedef implementation-defined pointer;
272 typedef T element_type;
273 typedef D deleter_type;
274
275 // constructors
Howard Hinnant1694d232011-05-28 14:41:13 +0000276 constexpr unique_ptr() noexcept;
277 explicit unique_ptr(pointer p) noexcept;
278 unique_ptr(pointer p, see below d) noexcept;
279 unique_ptr(pointer p, see below d) noexcept;
280 unique_ptr(unique_ptr&& u) noexcept;
281 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnante92c3d72010-08-19 18:39:17 +0000282
283 // destructor
Howard Hinnant324bb032010-08-22 00:02:43 +0000284 ~unique_ptr();
Howard Hinnante92c3d72010-08-19 18:39:17 +0000285
286 // assignment
Howard Hinnant1694d232011-05-28 14:41:13 +0000287 unique_ptr& operator=(unique_ptr&& u) noexcept;
288 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000289
290 // observers
291 T& operator[](size_t i) const;
Howard Hinnant1694d232011-05-28 14:41:13 +0000292 pointer get() const noexcept;
293 deleter_type& get_deleter() noexcept;
294 const deleter_type& get_deleter() const noexcept;
295 explicit operator bool() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000296
297 // modifiers
Howard Hinnant1694d232011-05-28 14:41:13 +0000298 pointer release() noexcept;
299 void reset(pointer p = pointer()) noexcept;
300 void reset(nullptr_t) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000301 template <class U> void reset(U) = delete;
Howard Hinnant1694d232011-05-28 14:41:13 +0000302 void swap(unique_ptr& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000303};
304
305template <class T, class D>
Howard Hinnant1694d232011-05-28 14:41:13 +0000306 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000307
308template <class T1, class D1, class T2, class D2>
309 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
310template <class T1, class D1, class T2, class D2>
311 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
312template <class T1, class D1, class T2, class D2>
313 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
314template <class T1, class D1, class T2, class D2>
315 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
316template <class T1, class D1, class T2, class D2>
317 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
318template <class T1, class D1, class T2, class D2>
319 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
320
Howard Hinnant1694d232011-05-28 14:41:13 +0000321template <class T, class D>
322 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
323template <class T, class D>
324 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
325template <class T, class D>
326 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
327template <class T, class D>
328 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
329
330template <class T, class D>
331 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
332template <class T, class D>
333 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
334template <class T, class D>
335 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
336template <class T, class D>
337 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
338template <class T, class D>
339 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
340template <class T, class D>
341 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
342template <class T, class D>
343 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
344template <class T, class D>
345 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
346
Howard Hinnante92c3d72010-08-19 18:39:17 +0000347class bad_weak_ptr
348 : public std::exception
349{
Howard Hinnant1694d232011-05-28 14:41:13 +0000350 bad_weak_ptr() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000351};
352
353template<class T>
354class shared_ptr
355{
356public:
357 typedef T element_type;
358
359 // constructors:
Howard Hinnant1694d232011-05-28 14:41:13 +0000360 constexpr shared_ptr() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000361 template<class Y> explicit shared_ptr(Y* p);
362 template<class Y, class D> shared_ptr(Y* p, D d);
363 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
364 template <class D> shared_ptr(nullptr_t p, D d);
365 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
Howard Hinnant1694d232011-05-28 14:41:13 +0000366 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
367 shared_ptr(const shared_ptr& r) noexcept;
368 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
369 shared_ptr(shared_ptr&& r) noexcept;
370 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000371 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
372 template<class Y> shared_ptr(auto_ptr<Y>&& r);
373 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
374 shared_ptr(nullptr_t) : shared_ptr() { }
375
376 // destructor:
377 ~shared_ptr();
378
379 // assignment:
Howard Hinnant1694d232011-05-28 14:41:13 +0000380 shared_ptr& operator=(const shared_ptr& r) noexcept;
381 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
382 shared_ptr& operator=(shared_ptr&& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000383 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
384 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
385 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
386
387 // modifiers:
Howard Hinnant1694d232011-05-28 14:41:13 +0000388 void swap(shared_ptr& r) noexcept;
389 void reset() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000390 template<class Y> void reset(Y* p);
391 template<class Y, class D> void reset(Y* p, D d);
392 template<class Y, class D, class A> void reset(Y* p, D d, A a);
393
Howard Hinnant1694d232011-05-28 14:41:13 +0000394 // observers:
395 T* get() const noexcept;
396 T& operator*() const noexcept;
397 T* operator->() const noexcept;
398 long use_count() const noexcept;
399 bool unique() const noexcept;
400 explicit operator bool() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000401 template<class U> bool owner_before(shared_ptr<U> const& b) const;
402 template<class U> bool owner_before(weak_ptr<U> const& b) const;
403};
404
405// shared_ptr comparisons:
406template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000407 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000408template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000409 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000410template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000411 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000412template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000413 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000414template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000415 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000416template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000417 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
418
419template <class T>
420 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
421template <class T>
422 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
423template <class T>
424 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
425template <class T>
426 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
427template <class T>
428 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
429template <class T>
430bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
431template <class T>
432 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
433template <class T>
434 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
435template <class T>
436 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
437template <class T>
438 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
439template <class T>
440 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
441template <class T>
442 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000443
444// shared_ptr specialized algorithms:
Howard Hinnant1694d232011-05-28 14:41:13 +0000445template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000446
447// shared_ptr casts:
448template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000449 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000450template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000451 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000452template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000453 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000454
455// shared_ptr I/O:
456template<class E, class T, class Y>
457 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
458
459// shared_ptr get_deleter:
Howard Hinnant1694d232011-05-28 14:41:13 +0000460template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000461
462template<class T, class... Args>
463 shared_ptr<T> make_shared(Args&&... args);
464template<class T, class A, class... Args>
465 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
466
467template<class T>
468class weak_ptr
469{
470public:
471 typedef T element_type;
472
473 // constructors
Howard Hinnant1694d232011-05-28 14:41:13 +0000474 constexpr weak_ptr() noexcept;
475 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
476 weak_ptr(weak_ptr const& r) noexcept;
477 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000478
479 // destructor
480 ~weak_ptr();
481
482 // assignment
Howard Hinnant1694d232011-05-28 14:41:13 +0000483 weak_ptr& operator=(weak_ptr const& r) noexcept;
484 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
485 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000486
487 // modifiers
Howard Hinnant1694d232011-05-28 14:41:13 +0000488 void swap(weak_ptr& r) noexcept;
489 void reset() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000490
491 // observers
Howard Hinnant1694d232011-05-28 14:41:13 +0000492 long use_count() const noexcept;
493 bool expired() const noexcept;
494 shared_ptr<T> lock() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000495 template<class U> bool owner_before(shared_ptr<U> const& b);
496 template<class U> bool owner_before(weak_ptr<U> const& b);
497};
498
499// weak_ptr specialized algorithms:
Howard Hinnant1694d232011-05-28 14:41:13 +0000500template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000501
502// class owner_less:
503template<class T> struct owner_less;
504
505template<class T>
506struct owner_less<shared_ptr<T>>
507 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
508{
509 typedef bool result_type;
510 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
511 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
512 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
513};
514
515template<class T>
516struct owner_less<weak_ptr<T>>
517 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
518{
519 typedef bool result_type;
520 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
521 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
522 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
523};
524
525template<class T>
526class enable_shared_from_this
527{
528protected:
Howard Hinnant1694d232011-05-28 14:41:13 +0000529 constexpr enable_shared_from_this() noexcept;
530 enable_shared_from_this(enable_shared_from_this const&) noexcept;
531 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000532 ~enable_shared_from_this();
533public:
534 shared_ptr<T> shared_from_this();
535 shared_ptr<T const> shared_from_this() const;
536};
537
538template<class T>
539 bool atomic_is_lock_free(const shared_ptr<T>* p);
540template<class T>
541 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
542template<class T>
543 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
544template<class T>
545 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
546template<class T>
547 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
548template<class T>
549 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
550template<class T>
551 shared_ptr<T>
552 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
553template<class T>
554 bool
555 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
556template<class T>
557 bool
558 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
559template<class T>
560 bool
561 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
562 shared_ptr<T> w, memory_order success,
563 memory_order failure);
564template<class T>
565 bool
566 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
567 shared_ptr<T> w, memory_order success,
568 memory_order failure);
569// Hash support
570template <class T> struct hash;
571template <class T, class D> struct hash<unique_ptr<T, D> >;
572template <class T> struct hash<shared_ptr<T> >;
573
574// Pointer safety
575enum class pointer_safety { relaxed, preferred, strict };
576void declare_reachable(void *p);
577template <class T> T *undeclare_reachable(T *p);
578void declare_no_pointers(char *p, size_t n);
579void undeclare_no_pointers(char *p, size_t n);
Howard Hinnant1694d232011-05-28 14:41:13 +0000580pointer_safety get_pointer_safety() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000581
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
583
584} // std
585
586*/
587
588#include <__config>
589#include <type_traits>
590#include <typeinfo>
591#include <cstddef>
592#include <cstdint>
593#include <new>
594#include <utility>
595#include <limits>
596#include <iterator>
597#include <__functional_base>
Howard Hinnant464aa5c2011-07-18 15:51:59 +0000598#include <iosfwd>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000599#include <tuple>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000600#include <cstring>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601#if defined(_LIBCPP_NO_EXCEPTIONS)
602 #include <cassert>
603#endif
604
Howard Hinnant66c6f972011-11-29 16:45:27 +0000605#include <__undef_min_max>
606
Howard Hinnant08e17472011-10-17 20:05:10 +0000607#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000609#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610
611_LIBCPP_BEGIN_NAMESPACE_STD
612
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613// addressof
614
615template <class _Tp>
616inline _LIBCPP_INLINE_VISIBILITY
617_Tp*
Howard Hinnant1694d232011-05-28 14:41:13 +0000618addressof(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619{
620 return (_Tp*)&(char&)__x;
621}
622
Douglas Gregor35d2fcf2011-06-22 22:17:44 +0000623#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
624// Objective-C++ Automatic Reference Counting uses qualified pointers
625// that require special addressof() signatures. When
626// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
627// itself is providing these definitions. Otherwise, we provide them.
628template <class _Tp>
629inline _LIBCPP_INLINE_VISIBILITY
630__strong _Tp*
631addressof(__strong _Tp& __x) _NOEXCEPT
632{
633 return &__x;
634}
635
636#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
637template <class _Tp>
638inline _LIBCPP_INLINE_VISIBILITY
639__weak _Tp*
640addressof(__weak _Tp& __x) _NOEXCEPT
641{
642 return &__x;
643}
644#endif
645
646template <class _Tp>
647inline _LIBCPP_INLINE_VISIBILITY
648__autoreleasing _Tp*
649addressof(__autoreleasing _Tp& __x) _NOEXCEPT
650{
651 return &__x;
652}
653
654template <class _Tp>
655inline _LIBCPP_INLINE_VISIBILITY
656__unsafe_unretained _Tp*
657addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
658{
659 return &__x;
660}
661#endif
662
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663template <class _Tp> class allocator;
664
665template <>
Howard Hinnant82894812010-09-22 16:48:34 +0000666class _LIBCPP_VISIBLE allocator<void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667{
668public:
669 typedef void* pointer;
670 typedef const void* const_pointer;
671 typedef void value_type;
672
673 template <class _Up> struct rebind {typedef allocator<_Up> other;};
674};
675
Howard Hinnanta1877872012-01-19 23:15:22 +0000676template <>
677class _LIBCPP_VISIBLE allocator<const void>
678{
679public:
680 typedef const void* pointer;
681 typedef const void* const_pointer;
682 typedef const void value_type;
683
684 template <class _Up> struct rebind {typedef allocator<_Up> other;};
685};
686
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687// pointer_traits
688
689template <class _Tp>
690struct __has_element_type
691{
692private:
693 struct __two {char _; char __;};
694 template <class _Up> static __two __test(...);
695 template <class _Up> static char __test(typename _Up::element_type* = 0);
696public:
697 static const bool value = sizeof(__test<_Tp>(0)) == 1;
698};
699
700template <class _Ptr, bool = __has_element_type<_Ptr>::value>
701struct __pointer_traits_element_type;
702
703template <class _Ptr>
704struct __pointer_traits_element_type<_Ptr, true>
705{
706 typedef typename _Ptr::element_type type;
707};
708
709#ifndef _LIBCPP_HAS_NO_VARIADICS
710
711template <template <class, class...> class _Sp, class _Tp, class ..._Args>
712struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
713{
714 typedef typename _Sp<_Tp, _Args...>::element_type type;
715};
716
717template <template <class, class...> class _Sp, class _Tp, class ..._Args>
718struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
719{
720 typedef _Tp type;
721};
722
Howard Hinnant324bb032010-08-22 00:02:43 +0000723#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724
725template <template <class> class _Sp, class _Tp>
726struct __pointer_traits_element_type<_Sp<_Tp>, true>
727{
728 typedef typename _Sp<_Tp>::element_type type;
729};
730
731template <template <class> class _Sp, class _Tp>
732struct __pointer_traits_element_type<_Sp<_Tp>, false>
733{
734 typedef _Tp type;
735};
736
737template <template <class, class> class _Sp, class _Tp, class _A0>
738struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
739{
740 typedef typename _Sp<_Tp, _A0>::element_type type;
741};
742
743template <template <class, class> class _Sp, class _Tp, class _A0>
744struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
745{
746 typedef _Tp type;
747};
748
749template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
750struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
751{
752 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
753};
754
755template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
756struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
757{
758 typedef _Tp type;
759};
760
761template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
762 class _A1, class _A2>
763struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
764{
765 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
766};
767
768template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
769 class _A1, class _A2>
770struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
771{
772 typedef _Tp type;
773};
774
Howard Hinnant324bb032010-08-22 00:02:43 +0000775#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776
777template <class _Tp>
778struct __has_difference_type
779{
780private:
781 struct __two {char _; char __;};
782 template <class _Up> static __two __test(...);
783 template <class _Up> static char __test(typename _Up::difference_type* = 0);
784public:
785 static const bool value = sizeof(__test<_Tp>(0)) == 1;
786};
787
788template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
789struct __pointer_traits_difference_type
790{
791 typedef ptrdiff_t type;
792};
793
794template <class _Ptr>
795struct __pointer_traits_difference_type<_Ptr, true>
796{
797 typedef typename _Ptr::difference_type type;
798};
799
800template <class _Tp, class _Up>
801struct __has_rebind
802{
803private:
804 struct __two {char _; char __;};
805 template <class _Xp> static __two __test(...);
806 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
807public:
808 static const bool value = sizeof(__test<_Tp>(0)) == 1;
809};
810
811template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
812struct __pointer_traits_rebind
813{
814#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
815 typedef typename _Tp::template rebind<_Up> type;
816#else
817 typedef typename _Tp::template rebind<_Up>::other type;
818#endif
819};
820
821#ifndef _LIBCPP_HAS_NO_VARIADICS
822
823template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
824struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
825{
826#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
827 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
828#else
829 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
830#endif
831};
832
833template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
834struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
835{
836 typedef _Sp<_Up, _Args...> type;
837};
838
Howard Hinnant324bb032010-08-22 00:02:43 +0000839#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840
841template <template <class> class _Sp, class _Tp, class _Up>
842struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
843{
844#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
845 typedef typename _Sp<_Tp>::template rebind<_Up> type;
846#else
847 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
848#endif
849};
850
851template <template <class> class _Sp, class _Tp, class _Up>
852struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
853{
854 typedef _Sp<_Up> type;
855};
856
857template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
858struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
859{
860#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
861 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
862#else
863 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
864#endif
865};
866
867template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
868struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
869{
870 typedef _Sp<_Up, _A0> type;
871};
872
873template <template <class, class, class> class _Sp, class _Tp, class _A0,
874 class _A1, class _Up>
875struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
876{
877#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
878 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
879#else
880 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
881#endif
882};
883
884template <template <class, class, class> class _Sp, class _Tp, class _A0,
885 class _A1, class _Up>
886struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
887{
888 typedef _Sp<_Up, _A0, _A1> type;
889};
890
891template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
892 class _A1, class _A2, class _Up>
893struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
894{
895#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
896 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
897#else
898 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
899#endif
900};
901
902template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
903 class _A1, class _A2, class _Up>
904struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
905{
906 typedef _Sp<_Up, _A0, _A1, _A2> type;
907};
908
Howard Hinnant324bb032010-08-22 00:02:43 +0000909#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000910
911template <class _Ptr>
Howard Hinnant82894812010-09-22 16:48:34 +0000912struct _LIBCPP_VISIBLE pointer_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913{
914 typedef _Ptr pointer;
915 typedef typename __pointer_traits_element_type<pointer>::type element_type;
916 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
917
918#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant6b41c602011-05-11 20:21:19 +0000919 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920#else
921 template <class _Up> struct rebind
922 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Howard Hinnant324bb032010-08-22 00:02:43 +0000923#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924
925private:
926 struct __nat {};
927public:
Howard Hinnant82894812010-09-22 16:48:34 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929 static pointer pointer_to(typename conditional<is_void<element_type>::value,
930 __nat, element_type>::type& __r)
931 {return pointer::pointer_to(__r);}
932};
933
934template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +0000935struct _LIBCPP_VISIBLE pointer_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936{
937 typedef _Tp* pointer;
938 typedef _Tp element_type;
939 typedef ptrdiff_t difference_type;
940
941#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
942 template <class _Up> using rebind = _Up*;
943#else
944 template <class _Up> struct rebind {typedef _Up* other;};
945#endif
946
947private:
948 struct __nat {};
949public:
Howard Hinnant82894812010-09-22 16:48:34 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant1694d232011-05-28 14:41:13 +0000952 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000953 {return _VSTD::addressof(__r);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954};
955
956// allocator_traits
957
958namespace __has_pointer_type_imp
959{
960 template <class _Up> static __two test(...);
961 template <class _Up> static char test(typename _Up::pointer* = 0);
962}
963
964template <class _Tp>
965struct __has_pointer_type
966 : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
967{
968};
969
970namespace __pointer_type_imp
971{
972
973template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
974struct __pointer_type
975{
976 typedef typename _Dp::pointer type;
977};
978
979template <class _Tp, class _Dp>
980struct __pointer_type<_Tp, _Dp, false>
981{
982 typedef _Tp* type;
983};
984
Howard Hinnant47761072010-11-18 01:40:00 +0000985} // __pointer_type_imp
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986
987template <class _Tp, class _Dp>
988struct __pointer_type
989{
990 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
991};
992
993template <class _Tp>
994struct __has_const_pointer
995{
996private:
997 struct __two {char _; char __;};
998 template <class _Up> static __two __test(...);
999 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1000public:
1001 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1002};
1003
1004template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1005struct __const_pointer
1006{
1007 typedef typename _Alloc::const_pointer type;
1008};
1009
1010template <class _Tp, class _Ptr, class _Alloc>
1011struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1012{
1013#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1014 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1015#else
1016 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1017#endif
1018};
1019
1020template <class _Tp>
1021struct __has_void_pointer
1022{
1023private:
1024 struct __two {char _; char __;};
1025 template <class _Up> static __two __test(...);
1026 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1027public:
1028 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1029};
1030
1031template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1032struct __void_pointer
1033{
1034 typedef typename _Alloc::void_pointer type;
1035};
1036
1037template <class _Ptr, class _Alloc>
1038struct __void_pointer<_Ptr, _Alloc, false>
1039{
1040#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1041 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1042#else
1043 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1044#endif
1045};
1046
1047template <class _Tp>
1048struct __has_const_void_pointer
1049{
1050private:
1051 struct __two {char _; char __;};
1052 template <class _Up> static __two __test(...);
1053 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1054public:
1055 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1056};
1057
1058template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1059struct __const_void_pointer
1060{
1061 typedef typename _Alloc::const_void_pointer type;
1062};
1063
1064template <class _Ptr, class _Alloc>
1065struct __const_void_pointer<_Ptr, _Alloc, false>
1066{
1067#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1068 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1069#else
1070 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1071#endif
1072};
1073
Howard Hinnant99968442011-11-29 18:15:50 +00001074template <class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001076_Tp*
1077__to_raw_pointer(_Tp* __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078{
1079 return __p;
1080}
1081
1082template <class _Pointer>
1083inline _LIBCPP_INLINE_VISIBILITY
1084typename pointer_traits<_Pointer>::element_type*
Howard Hinnant1694d232011-05-28 14:41:13 +00001085__to_raw_pointer(_Pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001087 return _VSTD::__to_raw_pointer(__p.operator->());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088}
1089
1090template <class _Tp>
1091struct __has_size_type
1092{
1093private:
1094 struct __two {char _; char __;};
1095 template <class _Up> static __two __test(...);
1096 template <class _Up> static char __test(typename _Up::size_type* = 0);
1097public:
1098 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1099};
1100
Howard Hinnant47761072010-11-18 01:40:00 +00001101template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102struct __size_type
1103{
Howard Hinnant47761072010-11-18 01:40:00 +00001104 typedef typename make_unsigned<_DiffType>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105};
1106
Howard Hinnant47761072010-11-18 01:40:00 +00001107template <class _Alloc, class _DiffType>
1108struct __size_type<_Alloc, _DiffType, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109{
1110 typedef typename _Alloc::size_type type;
1111};
1112
1113template <class _Tp>
1114struct __has_propagate_on_container_copy_assignment
1115{
1116private:
1117 struct __two {char _; char __;};
1118 template <class _Up> static __two __test(...);
1119 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1120public:
1121 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1122};
1123
1124template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1125struct __propagate_on_container_copy_assignment
1126{
1127 typedef false_type type;
1128};
1129
1130template <class _Alloc>
1131struct __propagate_on_container_copy_assignment<_Alloc, true>
1132{
1133 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1134};
1135
1136template <class _Tp>
1137struct __has_propagate_on_container_move_assignment
1138{
1139private:
1140 struct __two {char _; char __;};
1141 template <class _Up> static __two __test(...);
1142 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1143public:
1144 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1145};
1146
1147template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1148struct __propagate_on_container_move_assignment
1149{
1150 typedef false_type type;
1151};
1152
1153template <class _Alloc>
1154struct __propagate_on_container_move_assignment<_Alloc, true>
1155{
1156 typedef typename _Alloc::propagate_on_container_move_assignment type;
1157};
1158
1159template <class _Tp>
1160struct __has_propagate_on_container_swap
1161{
1162private:
1163 struct __two {char _; char __;};
1164 template <class _Up> static __two __test(...);
1165 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1166public:
1167 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1168};
1169
1170template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1171struct __propagate_on_container_swap
1172{
1173 typedef false_type type;
1174};
1175
1176template <class _Alloc>
1177struct __propagate_on_container_swap<_Alloc, true>
1178{
1179 typedef typename _Alloc::propagate_on_container_swap type;
1180};
1181
1182template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1183struct __has_rebind_other
1184{
1185private:
1186 struct __two {char _; char __;};
1187 template <class _Xp> static __two __test(...);
1188 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1189public:
1190 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1191};
1192
1193template <class _Tp, class _Up>
1194struct __has_rebind_other<_Tp, _Up, false>
1195{
1196 static const bool value = false;
1197};
1198
1199template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1200struct __allocator_traits_rebind
1201{
1202 typedef typename _Tp::template rebind<_Up>::other type;
1203};
1204
1205#ifndef _LIBCPP_HAS_NO_VARIADICS
1206
1207template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1208struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1209{
1210 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1211};
1212
1213template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1214struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1215{
1216 typedef _Alloc<_Up, _Args...> type;
1217};
1218
Howard Hinnant324bb032010-08-22 00:02:43 +00001219#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220
1221template <template <class> class _Alloc, class _Tp, class _Up>
1222struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1223{
1224 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1225};
1226
1227template <template <class> class _Alloc, class _Tp, class _Up>
1228struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1229{
1230 typedef _Alloc<_Up> type;
1231};
1232
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1234struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1235{
1236 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1237};
1238
1239template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1240struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1241{
1242 typedef _Alloc<_Up, _A0> type;
1243};
1244
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1246 class _A1, class _Up>
1247struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1248{
1249 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1250};
1251
1252template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1253 class _A1, class _Up>
1254struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1255{
1256 typedef _Alloc<_Up, _A0, _A1> type;
1257};
1258
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1260 class _A1, class _A2, class _Up>
1261struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1262{
1263 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1264};
1265
1266template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1267 class _A1, class _A2, class _Up>
1268struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1269{
1270 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1271};
1272
Howard Hinnant324bb032010-08-22 00:02:43 +00001273#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274
1275#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1276
1277template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1278auto
1279__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1280 -> decltype(__a.allocate(__sz, __p), true_type());
1281
1282template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1283auto
1284__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1285 -> false_type;
1286
1287template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1288struct __has_allocate_hint
1289 : integral_constant<bool,
1290 is_same<
1291 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1292 declval<_SizeType>(),
1293 declval<_ConstVoidPtr>())),
1294 true_type>::value>
1295{
1296};
1297
Howard Hinnant324bb032010-08-22 00:02:43 +00001298#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299
1300template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1301struct __has_allocate_hint
1302 : true_type
1303{
1304};
1305
Howard Hinnant324bb032010-08-22 00:02:43 +00001306#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307
Howard Hinnant23369ee2011-07-29 21:35:53 +00001308#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309
1310template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnant0949eed2011-06-30 21:18:19 +00001311decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1312 _VSTD::declval<_Args>()...),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313 true_type())
1314__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1315
1316template <class _Alloc, class _Pointer, class ..._Args>
1317false_type
1318__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1319
1320template <class _Alloc, class _Pointer, class ..._Args>
1321struct __has_construct
1322 : integral_constant<bool,
1323 is_same<
1324 decltype(__has_construct_test(declval<_Alloc>(),
1325 declval<_Pointer>(),
1326 declval<_Args>()...)),
1327 true_type>::value>
1328{
1329};
1330
1331template <class _Alloc, class _Pointer>
1332auto
1333__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1334 -> decltype(__a.destroy(__p), true_type());
1335
1336template <class _Alloc, class _Pointer>
1337auto
1338__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1339 -> false_type;
1340
1341template <class _Alloc, class _Pointer>
1342struct __has_destroy
1343 : integral_constant<bool,
1344 is_same<
1345 decltype(__has_destroy_test(declval<_Alloc>(),
1346 declval<_Pointer>())),
1347 true_type>::value>
1348{
1349};
1350
1351template <class _Alloc>
1352auto
1353__has_max_size_test(_Alloc&& __a)
1354 -> decltype(__a.max_size(), true_type());
1355
1356template <class _Alloc>
1357auto
1358__has_max_size_test(const volatile _Alloc& __a)
1359 -> false_type;
1360
1361template <class _Alloc>
1362struct __has_max_size
1363 : integral_constant<bool,
1364 is_same<
1365 decltype(__has_max_size_test(declval<_Alloc&>())),
1366 true_type>::value>
1367{
1368};
1369
1370template <class _Alloc>
1371auto
1372__has_select_on_container_copy_construction_test(_Alloc&& __a)
1373 -> decltype(__a.select_on_container_copy_construction(), true_type());
1374
1375template <class _Alloc>
1376auto
1377__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1378 -> false_type;
1379
1380template <class _Alloc>
1381struct __has_select_on_container_copy_construction
1382 : integral_constant<bool,
1383 is_same<
1384 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1385 true_type>::value>
1386{
1387};
1388
Howard Hinnant324bb032010-08-22 00:02:43 +00001389#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390
1391#ifndef _LIBCPP_HAS_NO_VARIADICS
1392
1393template <class _Alloc, class _Pointer, class ..._Args>
1394struct __has_construct
1395 : false_type
1396{
1397};
1398
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001399#else // _LIBCPP_HAS_NO_VARIADICS
1400
1401template <class _Alloc, class _Pointer, class _Args>
1402struct __has_construct
1403 : false_type
1404{
1405};
1406
Howard Hinnant324bb032010-08-22 00:02:43 +00001407#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408
1409template <class _Alloc, class _Pointer>
1410struct __has_destroy
1411 : false_type
1412{
1413};
1414
1415template <class _Alloc>
1416struct __has_max_size
1417 : true_type
1418{
1419};
1420
1421template <class _Alloc>
1422struct __has_select_on_container_copy_construction
1423 : false_type
1424{
1425};
1426
Howard Hinnant324bb032010-08-22 00:02:43 +00001427#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428
Howard Hinnant47761072010-11-18 01:40:00 +00001429template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1430struct __alloc_traits_difference_type
1431{
1432 typedef typename pointer_traits<_Ptr>::difference_type type;
1433};
1434
1435template <class _Alloc, class _Ptr>
1436struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1437{
1438 typedef typename _Alloc::difference_type type;
1439};
1440
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441template <class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001442struct _LIBCPP_VISIBLE allocator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001443{
1444 typedef _Alloc allocator_type;
1445 typedef typename allocator_type::value_type value_type;
1446
1447 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1448 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1449 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1450 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1451
Howard Hinnant47761072010-11-18 01:40:00 +00001452 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1453 typedef typename __size_type<allocator_type, difference_type>::type size_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454
1455 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1456 propagate_on_container_copy_assignment;
1457 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1458 propagate_on_container_move_assignment;
1459 typedef typename __propagate_on_container_swap<allocator_type>::type
1460 propagate_on_container_swap;
1461
1462#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1463 template <class _Tp> using rebind_alloc =
Howard Hinnant6b41c602011-05-11 20:21:19 +00001464 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
Howard Hinnant324bb032010-08-22 00:02:43 +00001466#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467 template <class _Tp> struct rebind_alloc
1468 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1469 template <class _Tp> struct rebind_traits
1470 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
Howard Hinnant324bb032010-08-22 00:02:43 +00001471#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472
Howard Hinnant82894812010-09-22 16:48:34 +00001473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474 static pointer allocate(allocator_type& __a, size_type __n)
1475 {return __a.allocate(__n);}
Howard Hinnant82894812010-09-22 16:48:34 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1478 {return allocate(__a, __n, __hint,
1479 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1480
Howard Hinnant82894812010-09-22 16:48:34 +00001481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001482 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 {__a.deallocate(__p, __n);}
1484
1485#ifndef _LIBCPP_HAS_NO_VARIADICS
1486 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1489 {__construct(__has_construct<allocator_type, pointer, _Args...>(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001490 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant324bb032010-08-22 00:02:43 +00001491#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001492 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494 static void construct(allocator_type& __a, _Tp* __p)
1495 {
1496 ::new ((void*)__p) _Tp();
1497 }
1498 template <class _Tp, class _A0>
Howard Hinnant82894812010-09-22 16:48:34 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1501 {
1502 ::new ((void*)__p) _Tp(__a0);
1503 }
1504 template <class _Tp, class _A0, class _A1>
Howard Hinnant82894812010-09-22 16:48:34 +00001505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1507 const _A1& __a1)
1508 {
1509 ::new ((void*)__p) _Tp(__a0, __a1);
1510 }
1511 template <class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant82894812010-09-22 16:48:34 +00001512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1514 const _A1& __a1, const _A2& __a2)
1515 {
1516 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1517 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001518#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519
1520 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 static void destroy(allocator_type& __a, _Tp* __p)
1523 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1524
Howard Hinnant82894812010-09-22 16:48:34 +00001525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 static size_type max_size(const allocator_type& __a)
1527 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1528
Howard Hinnant82894812010-09-22 16:48:34 +00001529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530 static allocator_type
1531 select_on_container_copy_construction(const allocator_type& __a)
1532 {return select_on_container_copy_construction(
1533 __has_select_on_container_copy_construction<const allocator_type>(),
1534 __a);}
1535
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001536 template <class _Ptr>
1537 _LIBCPP_INLINE_VISIBILITY
1538 static
1539 void
1540 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1541 {
1542 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1543 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1544 }
1545
1546 template <class _Tp>
1547 _LIBCPP_INLINE_VISIBILITY
1548 static
1549 typename enable_if
1550 <
1551 (is_same<allocator_type, allocator<_Tp> >::value
1552 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1553 is_trivially_move_constructible<_Tp>::value,
1554 void
1555 >::type
1556 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1557 {
1558 ptrdiff_t _Np = __end1 - __begin1;
1559 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1560 __begin2 += _Np;
1561 }
1562
1563 template <class _Ptr>
1564 _LIBCPP_INLINE_VISIBILITY
1565 static
1566 void
1567 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1568 {
1569 while (__end1 != __begin1)
1570 construct(__a, _VSTD::__to_raw_pointer(--__end2), _VSTD::move_if_noexcept(*--__end1));
1571 }
1572
1573 template <class _Tp>
1574 _LIBCPP_INLINE_VISIBILITY
1575 static
1576 typename enable_if
1577 <
1578 (is_same<allocator_type, allocator<_Tp> >::value
1579 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1580 is_trivially_move_constructible<_Tp>::value,
1581 void
1582 >::type
1583 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1584 {
1585 ptrdiff_t _Np = __end1 - __begin1;
1586 __end2 -= _Np;
1587 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1588 }
1589
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590private:
1591
Howard Hinnant82894812010-09-22 16:48:34 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593 static pointer allocate(allocator_type& __a, size_type __n,
1594 const_void_pointer __hint, true_type)
1595 {return __a.allocate(__n, __hint);}
Howard Hinnant82894812010-09-22 16:48:34 +00001596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597 static pointer allocate(allocator_type& __a, size_type __n,
Howard Hinnantec3773c2011-12-01 20:21:04 +00001598 const_void_pointer, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599 {return __a.allocate(__n);}
1600
1601#ifndef _LIBCPP_HAS_NO_VARIADICS
1602 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001605 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1609 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001610 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001612#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001613
1614 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1617 {__a.destroy(__p);}
1618 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620 static void __destroy(false_type, allocator_type&, _Tp* __p)
1621 {
1622 __p->~_Tp();
1623 }
1624
Howard Hinnant82894812010-09-22 16:48:34 +00001625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626 static size_type __max_size(true_type, const allocator_type& __a)
1627 {return __a.max_size();}
Howard Hinnant82894812010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 static size_type __max_size(false_type, const allocator_type&)
1630 {return numeric_limits<size_type>::max();}
1631
Howard Hinnant82894812010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633 static allocator_type
1634 select_on_container_copy_construction(true_type, const allocator_type& __a)
1635 {return __a.select_on_container_copy_construction();}
Howard Hinnant82894812010-09-22 16:48:34 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637 static allocator_type
1638 select_on_container_copy_construction(false_type, const allocator_type& __a)
1639 {return __a;}
1640};
1641
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642// allocator
1643
1644template <class _Tp>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001645class _LIBCPP_VISIBLE allocator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646{
1647public:
1648 typedef size_t size_type;
1649 typedef ptrdiff_t difference_type;
1650 typedef _Tp* pointer;
1651 typedef const _Tp* const_pointer;
1652 typedef _Tp& reference;
1653 typedef const _Tp& const_reference;
1654 typedef _Tp value_type;
1655
Howard Hinnant18884f42011-06-02 21:38:57 +00001656 typedef true_type propagate_on_container_move_assignment;
1657
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1659
Howard Hinnant1694d232011-05-28 14:41:13 +00001660 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1661 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1662 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001663 {return _VSTD::addressof(__x);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001664 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001665 {return _VSTD::addressof(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1667 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
Howard Hinnant1694d232011-05-28 14:41:13 +00001668 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1669 {::operator delete((void*)__p);}
1670 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1671 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001672#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673 template <class _Up, class... _Args>
1674 _LIBCPP_INLINE_VISIBILITY
1675 void
1676 construct(_Up* __p, _Args&&... __args)
1677 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001678 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001680#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681 _LIBCPP_INLINE_VISIBILITY
1682 void
1683 construct(pointer __p)
1684 {
1685 ::new((void*)__p) _Tp();
1686 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001687# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001688
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689 template <class _A0>
1690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001691 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 construct(pointer __p, _A0& __a0)
1693 {
1694 ::new((void*)__p) _Tp(__a0);
1695 }
1696 template <class _A0>
1697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001698 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 construct(pointer __p, const _A0& __a0)
1700 {
1701 ::new((void*)__p) _Tp(__a0);
1702 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001703# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704 template <class _A0, class _A1>
1705 _LIBCPP_INLINE_VISIBILITY
1706 void
1707 construct(pointer __p, _A0& __a0, _A1& __a1)
1708 {
1709 ::new((void*)__p) _Tp(__a0, __a1);
1710 }
1711 template <class _A0, class _A1>
1712 _LIBCPP_INLINE_VISIBILITY
1713 void
1714 construct(pointer __p, const _A0& __a0, _A1& __a1)
1715 {
1716 ::new((void*)__p) _Tp(__a0, __a1);
1717 }
1718 template <class _A0, class _A1>
1719 _LIBCPP_INLINE_VISIBILITY
1720 void
1721 construct(pointer __p, _A0& __a0, const _A1& __a1)
1722 {
1723 ::new((void*)__p) _Tp(__a0, __a1);
1724 }
1725 template <class _A0, class _A1>
1726 _LIBCPP_INLINE_VISIBILITY
1727 void
1728 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1729 {
1730 ::new((void*)__p) _Tp(__a0, __a1);
1731 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001732#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1734};
1735
Howard Hinnant57199402012-01-02 17:56:02 +00001736template <class _Tp>
1737class _LIBCPP_VISIBLE allocator<const _Tp>
1738{
1739public:
1740 typedef size_t size_type;
1741 typedef ptrdiff_t difference_type;
1742 typedef const _Tp* pointer;
1743 typedef const _Tp* const_pointer;
1744 typedef const _Tp& reference;
1745 typedef const _Tp& const_reference;
1746 typedef _Tp value_type;
1747
1748 typedef true_type propagate_on_container_move_assignment;
1749
1750 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1751
1752 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1753 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1754 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1755 {return _VSTD::addressof(__x);}
1756 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1757 {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1758 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1759 {::operator delete((void*)__p);}
1760 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1761 {return size_type(~0) / sizeof(_Tp);}
1762#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1763 template <class _Up, class... _Args>
1764 _LIBCPP_INLINE_VISIBILITY
1765 void
1766 construct(_Up* __p, _Args&&... __args)
1767 {
1768 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1769 }
1770#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1771 _LIBCPP_INLINE_VISIBILITY
1772 void
1773 construct(pointer __p)
1774 {
1775 ::new((void*)__p) _Tp();
1776 }
1777# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001778
Howard Hinnant57199402012-01-02 17:56:02 +00001779 template <class _A0>
1780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001781 void
Howard Hinnant57199402012-01-02 17:56:02 +00001782 construct(pointer __p, _A0& __a0)
1783 {
1784 ::new((void*)__p) _Tp(__a0);
1785 }
1786 template <class _A0>
1787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001788 void
Howard Hinnant57199402012-01-02 17:56:02 +00001789 construct(pointer __p, const _A0& __a0)
1790 {
1791 ::new((void*)__p) _Tp(__a0);
1792 }
Howard Hinnant57199402012-01-02 17:56:02 +00001793# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1794 template <class _A0, class _A1>
1795 _LIBCPP_INLINE_VISIBILITY
1796 void
1797 construct(pointer __p, _A0& __a0, _A1& __a1)
1798 {
1799 ::new((void*)__p) _Tp(__a0, __a1);
1800 }
1801 template <class _A0, class _A1>
1802 _LIBCPP_INLINE_VISIBILITY
1803 void
1804 construct(pointer __p, const _A0& __a0, _A1& __a1)
1805 {
1806 ::new((void*)__p) _Tp(__a0, __a1);
1807 }
1808 template <class _A0, class _A1>
1809 _LIBCPP_INLINE_VISIBILITY
1810 void
1811 construct(pointer __p, _A0& __a0, const _A1& __a1)
1812 {
1813 ::new((void*)__p) _Tp(__a0, __a1);
1814 }
1815 template <class _A0, class _A1>
1816 _LIBCPP_INLINE_VISIBILITY
1817 void
1818 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1819 {
1820 ::new((void*)__p) _Tp(__a0, __a1);
1821 }
1822#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1823 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1824};
1825
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826template <class _Tp, class _Up>
1827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001828bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829
1830template <class _Tp, class _Up>
1831inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001832bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833
1834template <class _OutputIterator, class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001835class _LIBCPP_VISIBLE raw_storage_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836 : public iterator<output_iterator_tag,
1837 _Tp, // purposefully not C++03
1838 ptrdiff_t, // purposefully not C++03
1839 _Tp*, // purposefully not C++03
1840 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1841{
1842private:
1843 _OutputIterator __x_;
1844public:
1845 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1846 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1847 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1848 {::new(&*__x_) _Tp(__element); return *this;}
1849 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1850 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1851 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1852};
1853
1854template <class _Tp>
1855pair<_Tp*, ptrdiff_t>
Howard Hinnant1694d232011-05-28 14:41:13 +00001856get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857{
1858 pair<_Tp*, ptrdiff_t> __r(0, 0);
1859 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1860 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1861 / sizeof(_Tp);
1862 if (__n > __m)
1863 __n = __m;
1864 while (__n > 0)
1865 {
1866 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1867 if (__r.first)
1868 {
1869 __r.second = __n;
1870 break;
1871 }
1872 __n /= 2;
1873 }
1874 return __r;
1875}
1876
1877template <class _Tp>
1878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001879void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880
1881template <class _Tp>
1882struct auto_ptr_ref
1883{
1884 _Tp* __ptr_;
1885};
1886
1887template<class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001888class _LIBCPP_VISIBLE auto_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889{
1890private:
1891 _Tp* __ptr_;
1892public:
1893 typedef _Tp element_type;
1894
1895 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1896 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1897 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1898 : __ptr_(__p.release()) {}
1899 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1900 {reset(__p.release()); return *this;}
1901 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1902 {reset(__p.release()); return *this;}
1903 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1904 {reset(__p.__ptr_); return *this;}
1905 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1906
1907 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1908 {return *__ptr_;}
1909 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1910 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1911 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1912 {
1913 _Tp* __t = __ptr_;
1914 __ptr_ = 0;
1915 return __t;
1916 }
1917 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1918 {
1919 if (__ptr_ != __p)
1920 delete __ptr_;
1921 __ptr_ = __p;
1922 }
1923
1924 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1925 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1926 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1927 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1928 {return auto_ptr<_Up>(release());}
1929};
1930
1931template <>
Howard Hinnant82894812010-09-22 16:48:34 +00001932class _LIBCPP_VISIBLE auto_ptr<void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933{
1934public:
1935 typedef void element_type;
1936};
1937
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1939 typename remove_cv<_T2>::type>::value,
Howard Hinnantd4cf2152011-12-11 20:31:33 +00001940 bool = is_empty<_T1>::value
1941#if __has_feature(is_final)
1942 && !__is_final(_T1)
1943#endif
1944 ,
1945 bool = is_empty<_T2>::value
1946#if __has_feature(is_final)
1947 && !__is_final(_T2)
1948#endif
1949 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950struct __libcpp_compressed_pair_switch;
1951
1952template <class _T1, class _T2, bool IsSame>
1953struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1954
1955template <class _T1, class _T2, bool IsSame>
1956struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1957
1958template <class _T1, class _T2, bool IsSame>
1959struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1960
1961template <class _T1, class _T2>
1962struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1963
1964template <class _T1, class _T2>
1965struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1966
1967template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1968class __libcpp_compressed_pair_imp;
1969
1970template <class _T1, class _T2>
1971class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1972{
1973private:
1974 _T1 __first_;
1975 _T2 __second_;
1976public:
1977 typedef _T1 _T1_param;
1978 typedef _T2 _T2_param;
1979
1980 typedef typename remove_reference<_T1>::type& _T1_reference;
1981 typedef typename remove_reference<_T2>::type& _T2_reference;
1982
1983 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1984 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1985
1986 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00001987 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001988 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00001989 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001990 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001992 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001993
Howard Hinnant61aa6012011-07-01 19:24:36 +00001994#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1995
1996 _LIBCPP_INLINE_VISIBILITY
1997 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
1998 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
1999 is_nothrow_copy_constructible<_T2>::value)
2000 : __first_(__p.first()),
2001 __second_(__p.second()) {}
2002
2003 _LIBCPP_INLINE_VISIBILITY
2004 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2005 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2006 is_nothrow_copy_assignable<_T2>::value)
2007 {
2008 __first_ = __p.first();
2009 __second_ = __p.second();
2010 return *this;
2011 }
2012
Howard Hinnant73d21a42010-09-04 23:28:19 +00002013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant61aa6012011-07-01 19:24:36 +00002014
2015 _LIBCPP_INLINE_VISIBILITY
2016 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002017 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2018 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002019 : __first_(_VSTD::forward<_T1>(__p.first())),
2020 __second_(_VSTD::forward<_T2>(__p.second())) {}
2021
2022 _LIBCPP_INLINE_VISIBILITY
2023 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2024 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2025 is_nothrow_move_assignable<_T2>::value)
2026 {
2027 __first_ = _VSTD::forward<_T1>(__p.first());
2028 __second_ = _VSTD::forward<_T2>(__p.second());
2029 return *this;
2030 }
2031
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002032#ifndef _LIBCPP_HAS_NO_VARIADICS
2033
2034 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2035 _LIBCPP_INLINE_VISIBILITY
2036 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2037 tuple<_Args1...> __first_args,
2038 tuple<_Args2...> __second_args,
2039 __tuple_indices<_I1...>,
2040 __tuple_indices<_I2...>)
2041 : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2042 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2043 {}
2044
2045#endif // _LIBCPP_HAS_NO_VARIADICS
2046
Howard Hinnant73d21a42010-09-04 23:28:19 +00002047#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002048
Howard Hinnant61aa6012011-07-01 19:24:36 +00002049#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2050
Howard Hinnant1694d232011-05-28 14:41:13 +00002051 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2052 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053
Howard Hinnant1694d232011-05-28 14:41:13 +00002054 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2055 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056
2057 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002058 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2059 __is_nothrow_swappable<_T1>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002061 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002062 swap(__first_, __x.__first_);
2063 swap(__second_, __x.__second_);
2064 }
2065};
2066
2067template <class _T1, class _T2>
2068class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2069 : private _T1
2070{
2071private:
2072 _T2 __second_;
2073public:
2074 typedef _T1 _T1_param;
2075 typedef _T2 _T2_param;
2076
2077 typedef _T1& _T1_reference;
2078 typedef typename remove_reference<_T2>::type& _T2_reference;
2079
2080 typedef const _T1& _T1_const_reference;
2081 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2082
2083 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002084 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002085 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002086 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002087 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002089 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090
Howard Hinnant61aa6012011-07-01 19:24:36 +00002091#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2092
2093 _LIBCPP_INLINE_VISIBILITY
2094 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2095 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2096 is_nothrow_copy_constructible<_T2>::value)
2097 : _T1(__p.first()), __second_(__p.second()) {}
2098
2099 _LIBCPP_INLINE_VISIBILITY
2100 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2101 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2102 is_nothrow_copy_assignable<_T2>::value)
2103 {
2104 _T1::operator=(__p.first());
2105 __second_ = __p.second();
2106 return *this;
2107 }
2108
Howard Hinnant73d21a42010-09-04 23:28:19 +00002109#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant61aa6012011-07-01 19:24:36 +00002110
2111 _LIBCPP_INLINE_VISIBILITY
2112 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002113 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2114 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002115 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002116
2117 _LIBCPP_INLINE_VISIBILITY
2118 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2119 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2120 is_nothrow_move_assignable<_T2>::value)
2121 {
2122 _T1::operator=(_VSTD::move(__p.first()));
2123 __second_ = _VSTD::forward<_T2>(__p.second());
2124 return *this;
2125 }
2126
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002127#ifndef _LIBCPP_HAS_NO_VARIADICS
2128
2129 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2130 _LIBCPP_INLINE_VISIBILITY
2131 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2132 tuple<_Args1...> __first_args,
2133 tuple<_Args2...> __second_args,
2134 __tuple_indices<_I1...>,
2135 __tuple_indices<_I2...>)
2136 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2137 __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2138 {}
2139
2140#endif // _LIBCPP_HAS_NO_VARIADICS
2141
Howard Hinnant73d21a42010-09-04 23:28:19 +00002142#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143
Howard Hinnant61aa6012011-07-01 19:24:36 +00002144#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2145
Howard Hinnant1694d232011-05-28 14:41:13 +00002146 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2147 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002148
Howard Hinnant1694d232011-05-28 14:41:13 +00002149 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2150 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002151
2152 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002153 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2154 __is_nothrow_swappable<_T1>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002156 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002157 swap(__second_, __x.__second_);
2158 }
2159};
2160
2161template <class _T1, class _T2>
2162class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2163 : private _T2
2164{
2165private:
2166 _T1 __first_;
2167public:
2168 typedef _T1 _T1_param;
2169 typedef _T2 _T2_param;
2170
2171 typedef typename remove_reference<_T1>::type& _T1_reference;
2172 typedef _T2& _T2_reference;
2173
2174 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2175 typedef const _T2& _T2_const_reference;
2176
2177 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2178 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002179 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002180 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002181 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant1694d232011-05-28 14:41:13 +00002183 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2184 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002185 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186
Howard Hinnant61aa6012011-07-01 19:24:36 +00002187#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2188
2189 _LIBCPP_INLINE_VISIBILITY
2190 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2191 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2192 is_nothrow_copy_constructible<_T2>::value)
2193 : _T2(__p.second()), __first_(__p.first()) {}
2194
2195 _LIBCPP_INLINE_VISIBILITY
2196 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2197 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2198 is_nothrow_copy_assignable<_T2>::value)
2199 {
2200 _T2::operator=(__p.second());
2201 __first_ = __p.first();
2202 return *this;
2203 }
2204
Howard Hinnant73d21a42010-09-04 23:28:19 +00002205#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant61aa6012011-07-01 19:24:36 +00002206
2207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002209 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2210 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002211 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002212
2213 _LIBCPP_INLINE_VISIBILITY
2214 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2215 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2216 is_nothrow_move_assignable<_T2>::value)
2217 {
2218 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2219 __first_ = _VSTD::move(__p.first());
2220 return *this;
2221 }
2222
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002223#ifndef _LIBCPP_HAS_NO_VARIADICS
2224
2225 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2226 _LIBCPP_INLINE_VISIBILITY
2227 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2228 tuple<_Args1...> __first_args,
2229 tuple<_Args2...> __second_args,
2230 __tuple_indices<_I1...>,
2231 __tuple_indices<_I2...>)
2232 : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2233 __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2234
2235 {}
2236
2237#endif // _LIBCPP_HAS_NO_VARIADICS
2238
Howard Hinnant73d21a42010-09-04 23:28:19 +00002239#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240
Howard Hinnant61aa6012011-07-01 19:24:36 +00002241#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2242
Howard Hinnant1694d232011-05-28 14:41:13 +00002243 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2244 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002245
Howard Hinnant1694d232011-05-28 14:41:13 +00002246 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2247 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248
2249 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002250 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2251 __is_nothrow_swappable<_T1>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002253 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 swap(__first_, __x.__first_);
2255 }
2256};
2257
2258template <class _T1, class _T2>
2259class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2260 : private _T1,
2261 private _T2
2262{
2263public:
2264 typedef _T1 _T1_param;
2265 typedef _T2 _T2_param;
2266
2267 typedef _T1& _T1_reference;
2268 typedef _T2& _T2_reference;
2269
2270 typedef const _T1& _T1_const_reference;
2271 typedef const _T2& _T2_const_reference;
2272
2273 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2274 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002275 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002277 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002279 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280
Howard Hinnant61aa6012011-07-01 19:24:36 +00002281#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2282
2283 _LIBCPP_INLINE_VISIBILITY
2284 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2285 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2286 is_nothrow_copy_constructible<_T2>::value)
2287 : _T1(__p.first()), _T2(__p.second()) {}
2288
2289 _LIBCPP_INLINE_VISIBILITY
2290 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2291 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2292 is_nothrow_copy_assignable<_T2>::value)
2293 {
2294 _T1::operator=(__p.first());
2295 _T2::operator=(__p.second());
2296 return *this;
2297 }
2298
Howard Hinnant73d21a42010-09-04 23:28:19 +00002299#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant61aa6012011-07-01 19:24:36 +00002300
2301 _LIBCPP_INLINE_VISIBILITY
2302 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002303 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2304 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002305 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002306
2307 _LIBCPP_INLINE_VISIBILITY
2308 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2309 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2310 is_nothrow_move_assignable<_T2>::value)
2311 {
2312 _T1::operator=(_VSTD::move(__p.first()));
2313 _T2::operator=(_VSTD::move(__p.second()));
2314 return *this;
2315 }
2316
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002317#ifndef _LIBCPP_HAS_NO_VARIADICS
2318
2319 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2320 _LIBCPP_INLINE_VISIBILITY
2321 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2322 tuple<_Args1...> __first_args,
2323 tuple<_Args2...> __second_args,
2324 __tuple_indices<_I1...>,
2325 __tuple_indices<_I2...>)
2326 : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2327 _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2328 {}
2329
2330#endif // _LIBCPP_HAS_NO_VARIADICS
2331
Howard Hinnant73d21a42010-09-04 23:28:19 +00002332#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333
Howard Hinnant61aa6012011-07-01 19:24:36 +00002334#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2335
Howard Hinnant1694d232011-05-28 14:41:13 +00002336 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2337 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338
Howard Hinnant1694d232011-05-28 14:41:13 +00002339 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2340 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341
Howard Hinnantec3773c2011-12-01 20:21:04 +00002342 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant1694d232011-05-28 14:41:13 +00002343 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2344 __is_nothrow_swappable<_T1>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345 {
2346 }
2347};
2348
2349template <class _T1, class _T2>
2350class __compressed_pair
2351 : private __libcpp_compressed_pair_imp<_T1, _T2>
2352{
2353 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2354public:
2355 typedef typename base::_T1_param _T1_param;
2356 typedef typename base::_T2_param _T2_param;
2357
2358 typedef typename base::_T1_reference _T1_reference;
2359 typedef typename base::_T2_reference _T2_reference;
2360
2361 typedef typename base::_T1_const_reference _T1_const_reference;
2362 typedef typename base::_T2_const_reference _T2_const_reference;
2363
2364 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002365 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002366 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002367 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002368 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002369 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002370 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371
Howard Hinnant61aa6012011-07-01 19:24:36 +00002372#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2373
2374 _LIBCPP_INLINE_VISIBILITY
2375 __compressed_pair(const __compressed_pair& __p)
2376 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2377 is_nothrow_copy_constructible<_T2>::value)
2378 : base(__p) {}
2379
2380 _LIBCPP_INLINE_VISIBILITY
2381 __compressed_pair& operator=(const __compressed_pair& __p)
2382 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2383 is_nothrow_copy_assignable<_T2>::value)
2384 {
2385 base::operator=(__p);
2386 return *this;
2387 }
2388
Howard Hinnant73d21a42010-09-04 23:28:19 +00002389#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant61aa6012011-07-01 19:24:36 +00002390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391 __compressed_pair(__compressed_pair&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002392 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2393 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002394 : base(_VSTD::move(__p)) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002395
2396 _LIBCPP_INLINE_VISIBILITY
2397 __compressed_pair& operator=(__compressed_pair&& __p)
2398 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2399 is_nothrow_move_assignable<_T2>::value)
2400 {
2401 base::operator=(_VSTD::move(__p));
2402 return *this;
2403 }
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002404
2405#ifndef _LIBCPP_HAS_NO_VARIADICS
2406
2407 template <class... _Args1, class... _Args2>
2408 _LIBCPP_INLINE_VISIBILITY
2409 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2410 tuple<_Args2...> __second_args)
Howard Hinnant57199402012-01-02 17:56:02 +00002411 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002412 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2413 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2414 {}
2415
2416#endif // _LIBCPP_HAS_NO_VARIADICS
2417
Howard Hinnant73d21a42010-09-04 23:28:19 +00002418#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002419
Howard Hinnant61aa6012011-07-01 19:24:36 +00002420#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2421
Howard Hinnant1694d232011-05-28 14:41:13 +00002422 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2423 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002424
Howard Hinnant1694d232011-05-28 14:41:13 +00002425 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2426 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002427
Howard Hinnant1694d232011-05-28 14:41:13 +00002428 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2429 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2430 __is_nothrow_swappable<_T1>::value)
2431 {base::swap(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432};
2433
2434template <class _T1, class _T2>
2435inline _LIBCPP_INLINE_VISIBILITY
2436void
2437swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant1694d232011-05-28 14:41:13 +00002438 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2439 __is_nothrow_swappable<_T1>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002440 {__x.swap(__y);}
2441
Howard Hinnant57199402012-01-02 17:56:02 +00002442// __same_or_less_cv_qualified
2443
2444template <class _Ptr1, class _Ptr2,
2445 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2446 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2447 >::value
2448 >
2449struct __same_or_less_cv_qualified_imp
2450 : is_convertible<_Ptr1, _Ptr2> {};
2451
2452template <class _Ptr1, class _Ptr2>
2453struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2454 : false_type {};
2455
2456template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2457 !is_pointer<_Ptr1>::value>
2458struct __same_or_less_cv_qualified
2459 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2460
2461template <class _Ptr1, class _Ptr2>
2462struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2463 : false_type {};
2464
2465// default_delete
2466
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002467template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00002468struct _LIBCPP_VISIBLE default_delete
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002469{
Howard Hinnant46e94932012-07-07 20:56:04 +00002470#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2471 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2472#else
2473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2474#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002475 template <class _Up>
2476 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant1694d232011-05-28 14:41:13 +00002477 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2478 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479 {
2480 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2481 delete __ptr;
2482 }
2483};
2484
2485template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00002486struct _LIBCPP_VISIBLE default_delete<_Tp[]>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002487{
Howard Hinnant8e843502011-12-18 21:19:44 +00002488public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002489#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2490 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2491#else
2492 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2493#endif
Howard Hinnant8e843502011-12-18 21:19:44 +00002494 template <class _Up>
2495 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant57199402012-01-02 17:56:02 +00002496 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnant8e843502011-12-18 21:19:44 +00002497 template <class _Up>
2498 _LIBCPP_INLINE_VISIBILITY
2499 void operator() (_Up* __ptr,
Howard Hinnant57199402012-01-02 17:56:02 +00002500 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002501 {
2502 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2503 delete [] __ptr;
2504 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002505};
2506
2507template <class _Tp, class _Dp = default_delete<_Tp> >
Howard Hinnant82894812010-09-22 16:48:34 +00002508class _LIBCPP_VISIBLE unique_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509{
2510public:
2511 typedef _Tp element_type;
2512 typedef _Dp deleter_type;
2513 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2514private:
2515 __compressed_pair<pointer, deleter_type> __ptr_;
2516
Howard Hinnant57199402012-01-02 17:56:02 +00002517#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002518 unique_ptr(unique_ptr&);
2519 template <class _Up, class _Ep>
2520 unique_ptr(unique_ptr<_Up, _Ep>&);
2521 unique_ptr& operator=(unique_ptr&);
2522 template <class _Up, class _Ep>
2523 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002524#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002525
2526 struct __nat {int __for_bool_;};
2527
2528 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2529 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2530public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002531 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 : __ptr_(pointer())
2533 {
2534 static_assert(!is_pointer<deleter_type>::value,
2535 "unique_ptr constructed with null function pointer deleter");
2536 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002537 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538 : __ptr_(pointer())
2539 {
2540 static_assert(!is_pointer<deleter_type>::value,
2541 "unique_ptr constructed with null function pointer deleter");
2542 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002543 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002544 : __ptr_(_VSTD::move(__p))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002545 {
2546 static_assert(!is_pointer<deleter_type>::value,
2547 "unique_ptr constructed with null function pointer deleter");
2548 }
2549
Howard Hinnant73d21a42010-09-04 23:28:19 +00002550#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002551 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2552 is_reference<deleter_type>::value,
2553 deleter_type,
2554 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002555 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002556 : __ptr_(__p, __d) {}
2557
2558 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002559 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002560 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002561 {
2562 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2563 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002564 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002565 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566 template <class _Up, class _Ep>
2567 _LIBCPP_INLINE_VISIBILITY
2568 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2569 typename enable_if
2570 <
2571 !is_array<_Up>::value &&
2572 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2573 is_convertible<_Ep, deleter_type>::value &&
2574 (
2575 !is_reference<deleter_type>::value ||
2576 is_same<deleter_type, _Ep>::value
2577 ),
2578 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002579 >::type = __nat()) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002580 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002581
2582 template <class _Up>
2583 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2584 typename enable_if<
2585 is_convertible<_Up*, _Tp*>::value &&
2586 is_same<_Dp, default_delete<_Tp> >::value,
2587 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002588 >::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002589 : __ptr_(__p.release())
2590 {
2591 }
2592
Howard Hinnant1694d232011-05-28 14:41:13 +00002593 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002594 {
2595 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002596 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002597 return *this;
2598 }
2599
2600 template <class _Up, class _Ep>
2601 _LIBCPP_INLINE_VISIBILITY
2602 typename enable_if
2603 <
Howard Hinnant57199402012-01-02 17:56:02 +00002604 !is_array<_Up>::value &&
2605 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2606 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 unique_ptr&
2608 >::type
Howard Hinnant1694d232011-05-28 14:41:13 +00002609 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 {
2611 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002612 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002613 return *this;
2614 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002615#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002616
2617 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2618 {
2619 return __rv<unique_ptr>(*this);
2620 }
2621
2622 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002623 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002624
2625 template <class _Up, class _Ep>
2626 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2627 {
2628 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002629 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 return *this;
2631 }
2632
2633 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002634 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002635
2636 template <class _Up>
2637 _LIBCPP_INLINE_VISIBILITY
2638 typename enable_if<
2639 is_convertible<_Up*, _Tp*>::value &&
2640 is_same<_Dp, default_delete<_Tp> >::value,
2641 unique_ptr&
2642 >::type
2643 operator=(auto_ptr<_Up> __p)
2644 {reset(__p.release()); return *this;}
2645
Howard Hinnant73d21a42010-09-04 23:28:19 +00002646#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2648
Howard Hinnant1694d232011-05-28 14:41:13 +00002649 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002650 {
2651 reset();
2652 return *this;
2653 }
2654
2655 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2656 {return *__ptr_.first();}
Howard Hinnant1694d232011-05-28 14:41:13 +00002657 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2658 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2659 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2660 {return __ptr_.second();}
2661 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2662 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002663 _LIBCPP_INLINE_VISIBILITY
2664 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2665 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666
Howard Hinnant1694d232011-05-28 14:41:13 +00002667 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 {
2669 pointer __t = __ptr_.first();
2670 __ptr_.first() = pointer();
2671 return __t;
2672 }
2673
Howard Hinnant1694d232011-05-28 14:41:13 +00002674 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675 {
2676 pointer __tmp = __ptr_.first();
2677 __ptr_.first() = __p;
2678 if (__tmp)
2679 __ptr_.second()(__tmp);
2680 }
2681
Howard Hinnant1694d232011-05-28 14:41:13 +00002682 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2683 {__ptr_.swap(__u.__ptr_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684};
2685
2686template <class _Tp, class _Dp>
Howard Hinnant82894812010-09-22 16:48:34 +00002687class _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002688{
2689public:
2690 typedef _Tp element_type;
2691 typedef _Dp deleter_type;
2692 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2693private:
2694 __compressed_pair<pointer, deleter_type> __ptr_;
2695
Howard Hinnant57199402012-01-02 17:56:02 +00002696#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002697 unique_ptr(unique_ptr&);
2698 template <class _Up>
2699 unique_ptr(unique_ptr<_Up>&);
2700 unique_ptr& operator=(unique_ptr&);
2701 template <class _Up>
2702 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002703#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704
2705 struct __nat {int __for_bool_;};
2706
2707 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2708 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2709public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002711 : __ptr_(pointer())
2712 {
2713 static_assert(!is_pointer<deleter_type>::value,
2714 "unique_ptr constructed with null function pointer deleter");
2715 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717 : __ptr_(pointer())
2718 {
2719 static_assert(!is_pointer<deleter_type>::value,
2720 "unique_ptr constructed with null function pointer deleter");
2721 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002722#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00002723 template <class _Pp,
Howard Hinnant57199402012-01-02 17:56:02 +00002724 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002725 >
Howard Hinnant99968442011-11-29 18:15:50 +00002726 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002727 : __ptr_(__p)
2728 {
2729 static_assert(!is_pointer<deleter_type>::value,
2730 "unique_ptr constructed with null function pointer deleter");
2731 }
2732
Howard Hinnant99968442011-11-29 18:15:50 +00002733 template <class _Pp,
Howard Hinnant57199402012-01-02 17:56:02 +00002734 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735 >
Howard Hinnant99968442011-11-29 18:15:50 +00002736 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002737 is_reference<deleter_type>::value,
2738 deleter_type,
2739 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002740 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 : __ptr_(__p, __d) {}
2742
2743 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2744 is_reference<deleter_type>::value,
2745 deleter_type,
2746 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002747 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002748 : __ptr_(pointer(), __d) {}
2749
Howard Hinnant99968442011-11-29 18:15:50 +00002750 template <class _Pp,
Howard Hinnant57199402012-01-02 17:56:02 +00002751 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752 >
Howard Hinnant99968442011-11-29 18:15:50 +00002753 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002754 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002755 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756 {
2757 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2758 }
2759
2760 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002761 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002762 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763 {
2764 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2765 }
2766
Howard Hinnant1694d232011-05-28 14:41:13 +00002767 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002768 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769
Howard Hinnant1694d232011-05-28 14:41:13 +00002770 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002771 {
2772 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002773 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002774 return *this;
2775 }
Howard Hinnant8e843502011-12-18 21:19:44 +00002776
2777 template <class _Up, class _Ep>
2778 _LIBCPP_INLINE_VISIBILITY
2779 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2780 typename enable_if
2781 <
2782 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002783 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnant8e843502011-12-18 21:19:44 +00002784 && is_convertible<_Ep, deleter_type>::value &&
2785 (
2786 !is_reference<deleter_type>::value ||
2787 is_same<deleter_type, _Ep>::value
2788 ),
2789 __nat
2790 >::type = __nat()
2791 ) _NOEXCEPT
2792 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2793
2794
2795 template <class _Up, class _Ep>
2796 _LIBCPP_INLINE_VISIBILITY
2797 typename enable_if
2798 <
2799 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002800 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2801 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant8e843502011-12-18 21:19:44 +00002802 unique_ptr&
2803 >::type
2804 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2805 {
2806 reset(__u.release());
2807 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2808 return *this;
2809 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002810#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002811
2812 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2813 : __ptr_(__p)
2814 {
2815 static_assert(!is_pointer<deleter_type>::value,
2816 "unique_ptr constructed with null function pointer deleter");
2817 }
2818
2819 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002820 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821
2822 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002823 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824
2825 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2826 {
2827 return __rv<unique_ptr>(*this);
2828 }
2829
2830 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002831 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832
2833 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2834 {
2835 reset(__u->release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002836 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002837 return *this;
2838 }
2839
Howard Hinnant73d21a42010-09-04 23:28:19 +00002840#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002841 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2842
Howard Hinnant1694d232011-05-28 14:41:13 +00002843 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002844 {
2845 reset();
2846 return *this;
2847 }
2848
2849 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2850 {return __ptr_.first()[__i];}
Howard Hinnant1694d232011-05-28 14:41:13 +00002851 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2852 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2853 {return __ptr_.second();}
2854 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2855 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002856 _LIBCPP_INLINE_VISIBILITY
2857 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2858 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859
Howard Hinnant1694d232011-05-28 14:41:13 +00002860 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861 {
2862 pointer __t = __ptr_.first();
2863 __ptr_.first() = pointer();
2864 return __t;
2865 }
2866
Howard Hinnant73d21a42010-09-04 23:28:19 +00002867#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00002868 template <class _Pp,
Howard Hinnant57199402012-01-02 17:56:02 +00002869 class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870 >
Howard Hinnant99968442011-11-29 18:15:50 +00002871 _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002872 {
2873 pointer __tmp = __ptr_.first();
2874 __ptr_.first() = __p;
2875 if (__tmp)
2876 __ptr_.second()(__tmp);
2877 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002878 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002879 {
2880 pointer __tmp = __ptr_.first();
2881 __ptr_.first() = nullptr;
2882 if (__tmp)
2883 __ptr_.second()(__tmp);
2884 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002885 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002886 {
2887 pointer __tmp = __ptr_.first();
2888 __ptr_.first() = nullptr;
2889 if (__tmp)
2890 __ptr_.second()(__tmp);
2891 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002892#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002893 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2894 {
2895 pointer __tmp = __ptr_.first();
2896 __ptr_.first() = __p;
2897 if (__tmp)
2898 __ptr_.second()(__tmp);
2899 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002900#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002901
2902 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2903private:
Howard Hinnant324bb032010-08-22 00:02:43 +00002904
Howard Hinnant73d21a42010-09-04 23:28:19 +00002905#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002906 template <class _Up>
2907 explicit unique_ptr(_Up);
2908 template <class _Up>
2909 unique_ptr(_Up __u,
2910 typename conditional<
2911 is_reference<deleter_type>::value,
2912 deleter_type,
2913 typename add_lvalue_reference<const deleter_type>::type>::type,
2914 typename enable_if
2915 <
2916 is_convertible<_Up, pointer>::value,
2917 __nat
2918 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00002919#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920};
2921
2922template <class _Tp, class _Dp>
2923inline _LIBCPP_INLINE_VISIBILITY
2924void
Howard Hinnant1694d232011-05-28 14:41:13 +00002925swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002926
2927template <class _T1, class _D1, class _T2, class _D2>
2928inline _LIBCPP_INLINE_VISIBILITY
2929bool
2930operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2931
2932template <class _T1, class _D1, class _T2, class _D2>
2933inline _LIBCPP_INLINE_VISIBILITY
2934bool
2935operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2936
2937template <class _T1, class _D1, class _T2, class _D2>
2938inline _LIBCPP_INLINE_VISIBILITY
2939bool
Howard Hinnant3fadda32012-02-21 21:02:58 +00002940operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2941{
2942 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2943 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2944 typedef typename common_type<_P1, _P2>::type _V;
2945 return less<_V>()(__x.get(), __y.get());
2946}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002947
2948template <class _T1, class _D1, class _T2, class _D2>
2949inline _LIBCPP_INLINE_VISIBILITY
2950bool
2951operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2952
2953template <class _T1, class _D1, class _T2, class _D2>
2954inline _LIBCPP_INLINE_VISIBILITY
2955bool
2956operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2957
2958template <class _T1, class _D1, class _T2, class _D2>
2959inline _LIBCPP_INLINE_VISIBILITY
2960bool
2961operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2962
Howard Hinnant3fadda32012-02-21 21:02:58 +00002963template <class _T1, class _D1>
2964inline _LIBCPP_INLINE_VISIBILITY
2965bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002966operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002967{
2968 return !__x;
2969}
2970
2971template <class _T1, class _D1>
2972inline _LIBCPP_INLINE_VISIBILITY
2973bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002974operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002975{
2976 return !__x;
2977}
2978
2979template <class _T1, class _D1>
2980inline _LIBCPP_INLINE_VISIBILITY
2981bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002982operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002983{
2984 return static_cast<bool>(__x);
2985}
2986
2987template <class _T1, class _D1>
2988inline _LIBCPP_INLINE_VISIBILITY
2989bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002990operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002991{
2992 return static_cast<bool>(__x);
2993}
2994
2995template <class _T1, class _D1>
2996inline _LIBCPP_INLINE_VISIBILITY
2997bool
2998operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2999{
3000 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3001 return less<_P1>()(__x.get(), nullptr);
3002}
3003
3004template <class _T1, class _D1>
3005inline _LIBCPP_INLINE_VISIBILITY
3006bool
3007operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3008{
3009 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3010 return less<_P1>()(nullptr, __x.get());
3011}
3012
3013template <class _T1, class _D1>
3014inline _LIBCPP_INLINE_VISIBILITY
3015bool
3016operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3017{
3018 return nullptr < __x;
3019}
3020
3021template <class _T1, class _D1>
3022inline _LIBCPP_INLINE_VISIBILITY
3023bool
3024operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3025{
3026 return __x < nullptr;
3027}
3028
3029template <class _T1, class _D1>
3030inline _LIBCPP_INLINE_VISIBILITY
3031bool
3032operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3033{
3034 return !(nullptr < __x);
3035}
3036
3037template <class _T1, class _D1>
3038inline _LIBCPP_INLINE_VISIBILITY
3039bool
3040operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3041{
3042 return !(__x < nullptr);
3043}
3044
3045template <class _T1, class _D1>
3046inline _LIBCPP_INLINE_VISIBILITY
3047bool
3048operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3049{
3050 return !(__x < nullptr);
3051}
3052
3053template <class _T1, class _D1>
3054inline _LIBCPP_INLINE_VISIBILITY
3055bool
3056operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3057{
3058 return !(nullptr < __x);
3059}
3060
Howard Hinnant87073e42012-05-01 15:37:54 +00003061#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3062
3063template <class _Tp, class _Dp>
3064inline _LIBCPP_INLINE_VISIBILITY
3065unique_ptr<_Tp, _Dp>
3066move(unique_ptr<_Tp, _Dp>& __t)
3067{
3068 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3069}
3070
3071#endif
3072
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00003073template <class _Tp> struct hash;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003074
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003075// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3076// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3077// multiplication, which can be very slow on 32-bit systems.
Howard Hinnant40c13d32011-12-05 00:08:45 +00003078template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003079struct __murmur2_or_cityhash;
Howard Hinnant40c13d32011-12-05 00:08:45 +00003080
3081template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003082struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003083{
3084 _Size operator()(const void* __key, _Size __len);
3085};
3086
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003087// murmur2
Howard Hinnant40c13d32011-12-05 00:08:45 +00003088template <class _Size>
3089_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003090__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003091{
3092 const _Size __m = 0x5bd1e995;
3093 const _Size __r = 24;
3094 _Size __h = __len;
3095 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3096 for (; __len >= 4; __data += 4, __len -= 4)
3097 {
3098 _Size __k = *(const _Size*)__data;
3099 __k *= __m;
3100 __k ^= __k >> __r;
3101 __k *= __m;
3102 __h *= __m;
3103 __h ^= __k;
3104 }
3105 switch (__len)
3106 {
3107 case 3:
3108 __h ^= __data[2] << 16;
3109 case 2:
3110 __h ^= __data[1] << 8;
3111 case 1:
3112 __h ^= __data[0];
3113 __h *= __m;
3114 }
3115 __h ^= __h >> 13;
3116 __h *= __m;
3117 __h ^= __h >> 15;
3118 return __h;
3119}
3120
3121template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003122struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003123{
3124 _Size operator()(const void* __key, _Size __len);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003125
3126 private:
3127 // Some primes between 2^63 and 2^64.
3128 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3129 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3130 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3131 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3132
3133 static _Size __rotate(_Size __val, int __shift) {
3134 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3135 }
3136
3137 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3138 return (__val >> __shift) | (__val << (64 - __shift));
3139 }
3140
3141 static _Size __shift_mix(_Size __val) {
3142 return __val ^ (__val >> 47);
3143 }
3144
3145 static _Size __hash_len_16(_Size __u, _Size __v) {
3146 const _Size __mul = 0x9ddfea08eb382d69ULL;
3147 _Size __a = (__u ^ __v) * __mul;
3148 __a ^= (__a >> 47);
3149 _Size __b = (__v ^ __a) * __mul;
3150 __b ^= (__b >> 47);
3151 __b *= __mul;
3152 return __b;
3153 }
3154
3155 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3156 if (__len > 8) {
3157 const _Size __a = *(const _Size*)__s;
3158 const _Size __b = *(const _Size*)(__s + __len - 8);
3159 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3160 }
3161 if (__len >= 4) {
3162 const uint32_t __a = *(const uint32_t*)(__s);
3163 const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
3164 return __hash_len_16(__len + (__a << 3), __b);
3165 }
3166 if (__len > 0) {
3167 const unsigned char __a = __s[0];
3168 const unsigned char __b = __s[__len >> 1];
3169 const unsigned char __c = __s[__len - 1];
3170 const uint32_t __y = static_cast<uint32_t>(__a) +
3171 (static_cast<uint32_t>(__b) << 8);
3172 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3173 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3174 }
3175 return __k2;
3176 }
3177
3178 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3179 const _Size __a = *(const _Size*)(__s) * __k1;
3180 const _Size __b = *(const _Size*)(__s + 8);
3181 const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
3182 const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
3183 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3184 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3185 }
3186
3187 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3188 // Callers do best to use "random-looking" values for a and b.
3189 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3190 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3191 __a += __w;
3192 __b = __rotate(__b + __a + __z, 21);
3193 const _Size __c = __a;
3194 __a += __x;
3195 __a += __y;
3196 __b += __rotate(__a, 44);
3197 return pair<_Size, _Size>(__a + __z, __b + __c);
3198 }
3199
3200 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3201 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3202 const char* __s, _Size __a, _Size __b) {
3203 return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
3204 *(const _Size*)(__s + 8),
3205 *(const _Size*)(__s + 16),
3206 *(const _Size*)(__s + 24),
3207 __a,
3208 __b);
3209 }
3210
3211 // Return an 8-byte hash for 33 to 64 bytes.
3212 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3213 _Size __z = *(const _Size*)(__s + 24);
3214 _Size __a = *(const _Size*)(__s) +
3215 (__len + *(const _Size*)(__s + __len - 16)) * __k0;
3216 _Size __b = __rotate(__a + __z, 52);
3217 _Size __c = __rotate(__a, 37);
3218 __a += *(const _Size*)(__s + 8);
3219 __c += __rotate(__a, 7);
3220 __a += *(const _Size*)(__s + 16);
3221 _Size __vf = __a + __z;
3222 _Size __vs = __b + __rotate(__a, 31) + __c;
3223 __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
3224 __z += *(const _Size*)(__s + __len - 8);
3225 __b = __rotate(__a + __z, 52);
3226 __c = __rotate(__a, 37);
3227 __a += *(const _Size*)(__s + __len - 24);
3228 __c += __rotate(__a, 7);
3229 __a += *(const _Size*)(__s + __len - 16);
3230 _Size __wf = __a + __z;
3231 _Size __ws = __b + __rotate(__a, 31) + __c;
3232 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3233 return __shift_mix(__r * __k0 + __vs) * __k2;
3234 }
Howard Hinnant40c13d32011-12-05 00:08:45 +00003235};
3236
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003237// cityhash64
Howard Hinnant40c13d32011-12-05 00:08:45 +00003238template <class _Size>
3239_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003240__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003241{
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003242 const char* __s = static_cast<const char*>(__key);
3243 if (__len <= 32) {
3244 if (__len <= 16) {
3245 return __hash_len_0_to_16(__s, __len);
3246 } else {
3247 return __hash_len_17_to_32(__s, __len);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003248 }
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003249 } else if (__len <= 64) {
3250 return __hash_len_33_to_64(__s, __len);
3251 }
3252
3253 // For strings over 64 bytes we hash the end first, and then as we
3254 // loop we keep 56 bytes of state: v, w, x, y, and z.
3255 _Size __x = *(const _Size*)(__s + __len - 40);
3256 _Size __y = *(const _Size*)(__s + __len - 16) +
3257 *(const _Size*)(__s + __len - 56);
3258 _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
3259 *(const _Size*)(__s + __len - 24));
3260 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3261 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3262 __x = __x * __k1 + *(const _Size*)(__s);
3263
3264 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3265 __len = (__len - 1) & ~static_cast<_Size>(63);
3266 do {
3267 __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
3268 __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
3269 __x ^= __w.second;
3270 __y += __v.first + *(const _Size*)(__s + 40);
3271 __z = __rotate(__z + __w.first, 33) * __k1;
3272 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3273 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3274 __y + *(const _Size*)(__s + 16));
3275 std::swap(__z, __x);
3276 __s += 64;
3277 __len -= 64;
3278 } while (__len != 0);
3279 return __hash_len_16(
3280 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3281 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003282}
3283
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003284template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3285struct __scalar_hash;
3286
3287template <class _Tp>
3288struct __scalar_hash<_Tp, 0>
3289 : public unary_function<_Tp, size_t>
Howard Hinnant21aefc32010-06-03 16:42:57 +00003290{
Howard Hinnant82894812010-09-22 16:48:34 +00003291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003292 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003293 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003294 union
3295 {
3296 _Tp __t;
3297 size_t __a;
3298 } __u;
3299 __u.__a = 0;
3300 __u.__t = __v;
3301 return __u.__a;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003302 }
3303};
3304
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003305template <class _Tp>
3306struct __scalar_hash<_Tp, 1>
3307 : public unary_function<_Tp, size_t>
3308{
3309 _LIBCPP_INLINE_VISIBILITY
3310 size_t operator()(_Tp __v) const _NOEXCEPT
3311 {
3312 union
3313 {
3314 _Tp __t;
3315 size_t __a;
3316 } __u;
3317 __u.__t = __v;
3318 return __u.__a;
3319 }
3320};
3321
3322template <class _Tp>
3323struct __scalar_hash<_Tp, 2>
3324 : public unary_function<_Tp, size_t>
3325{
3326 _LIBCPP_INLINE_VISIBILITY
3327 size_t operator()(_Tp __v) const _NOEXCEPT
3328 {
3329 union
3330 {
3331 _Tp __t;
3332 struct
3333 {
3334 size_t __a;
3335 size_t __b;
3336 };
3337 } __u;
3338 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003339 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003340 }
3341};
3342
3343template <class _Tp>
3344struct __scalar_hash<_Tp, 3>
3345 : public unary_function<_Tp, size_t>
3346{
3347 _LIBCPP_INLINE_VISIBILITY
3348 size_t operator()(_Tp __v) const _NOEXCEPT
3349 {
3350 union
3351 {
3352 _Tp __t;
3353 struct
3354 {
3355 size_t __a;
3356 size_t __b;
3357 size_t __c;
3358 };
3359 } __u;
3360 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003361 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003362 }
3363};
3364
3365template <class _Tp>
3366struct __scalar_hash<_Tp, 4>
3367 : public unary_function<_Tp, size_t>
3368{
3369 _LIBCPP_INLINE_VISIBILITY
3370 size_t operator()(_Tp __v) const _NOEXCEPT
3371 {
3372 union
3373 {
3374 _Tp __t;
3375 struct
3376 {
3377 size_t __a;
3378 size_t __b;
3379 size_t __c;
3380 size_t __d;
3381 };
3382 } __u;
3383 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003384 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003385 }
3386};
3387
3388template<class _Tp>
3389struct _LIBCPP_VISIBLE hash<_Tp*>
3390 : public __scalar_hash<_Tp*>
3391{
3392};
3393
Howard Hinnant21aefc32010-06-03 16:42:57 +00003394template <class _Tp, class _Dp>
Howard Hinnant82894812010-09-22 16:48:34 +00003395struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00003396{
3397 typedef unique_ptr<_Tp, _Dp> argument_type;
3398 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00003399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003400 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003401 {
3402 typedef typename argument_type::pointer pointer;
3403 return hash<pointer>()(__ptr.get());
3404 }
3405};
3406
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003407struct __destruct_n
3408{
3409private:
3410 size_t size;
3411
3412 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003413 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3415
3416 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003417 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003418 {}
3419
Howard Hinnant1694d232011-05-28 14:41:13 +00003420 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003421 {++size;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003422 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003423 {}
3424
Howard Hinnant1694d232011-05-28 14:41:13 +00003425 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003426 {size = __s;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003427 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003428 {}
3429public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003430 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3431 : size(__s) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003432
3433 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003434 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003435 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003436
3437 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003438 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003439 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003440
3441 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003442 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003443 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003444};
3445
3446template <class _Alloc>
3447class __allocator_destructor
3448{
3449 typedef allocator_traits<_Alloc> __alloc_traits;
3450public:
3451 typedef typename __alloc_traits::pointer pointer;
3452 typedef typename __alloc_traits::size_type size_type;
3453private:
3454 _Alloc& __alloc_;
3455 size_type __s_;
3456public:
3457 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant1694d232011-05-28 14:41:13 +00003458 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459 : __alloc_(__a), __s_(__s) {}
Howard Hinnant82894812010-09-22 16:48:34 +00003460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003461 void operator()(pointer __p) _NOEXCEPT
3462 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003463};
3464
3465template <class _InputIterator, class _ForwardIterator>
3466_ForwardIterator
3467uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3468{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003470#ifndef _LIBCPP_NO_EXCEPTIONS
3471 _ForwardIterator __s = __r;
3472 try
3473 {
3474#endif
3475 for (; __f != __l; ++__f, ++__r)
3476 ::new(&*__r) value_type(*__f);
3477#ifndef _LIBCPP_NO_EXCEPTIONS
3478 }
3479 catch (...)
3480 {
3481 for (; __s != __r; ++__s)
3482 __s->~value_type();
3483 throw;
3484 }
3485#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486 return __r;
3487}
3488
3489template <class _InputIterator, class _Size, class _ForwardIterator>
3490_ForwardIterator
3491uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3492{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003494#ifndef _LIBCPP_NO_EXCEPTIONS
3495 _ForwardIterator __s = __r;
3496 try
3497 {
3498#endif
3499 for (; __n > 0; ++__f, ++__r, --__n)
3500 ::new(&*__r) value_type(*__f);
3501#ifndef _LIBCPP_NO_EXCEPTIONS
3502 }
3503 catch (...)
3504 {
3505 for (; __s != __r; ++__s)
3506 __s->~value_type();
3507 throw;
3508 }
3509#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510 return __r;
3511}
3512
3513template <class _ForwardIterator, class _Tp>
3514void
3515uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3516{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003518#ifndef _LIBCPP_NO_EXCEPTIONS
3519 _ForwardIterator __s = __f;
3520 try
3521 {
3522#endif
3523 for (; __f != __l; ++__f)
3524 ::new(&*__f) value_type(__x);
3525#ifndef _LIBCPP_NO_EXCEPTIONS
3526 }
3527 catch (...)
3528 {
3529 for (; __s != __f; ++__s)
3530 __s->~value_type();
3531 throw;
3532 }
3533#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003534}
3535
3536template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003537_ForwardIterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003538uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3539{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003540 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003541#ifndef _LIBCPP_NO_EXCEPTIONS
3542 _ForwardIterator __s = __f;
3543 try
3544 {
3545#endif
3546 for (; __n > 0; ++__f, --__n)
3547 ::new(&*__f) value_type(__x);
3548#ifndef _LIBCPP_NO_EXCEPTIONS
3549 }
3550 catch (...)
3551 {
3552 for (; __s != __f; ++__s)
3553 __s->~value_type();
3554 throw;
3555 }
3556#endif
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003557 return __f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003558}
3559
Howard Hinnant82894812010-09-22 16:48:34 +00003560class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003561 : public std::exception
3562{
3563public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003564 virtual ~bad_weak_ptr() _NOEXCEPT;
3565 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566};
3567
3568template<class _Tp> class weak_ptr;
3569
3570class __shared_count
3571{
3572 __shared_count(const __shared_count&);
3573 __shared_count& operator=(const __shared_count&);
3574
3575protected:
3576 long __shared_owners_;
3577 virtual ~__shared_count();
3578private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003579 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003580
3581public:
Howard Hinnant82894812010-09-22 16:48:34 +00003582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003583 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003584 : __shared_owners_(__refs) {}
3585
Howard Hinnant1694d232011-05-28 14:41:13 +00003586 void __add_shared() _NOEXCEPT;
3587 bool __release_shared() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003589 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590};
3591
3592class __shared_weak_count
3593 : private __shared_count
3594{
3595 long __shared_weak_owners_;
3596
3597public:
Howard Hinnant82894812010-09-22 16:48:34 +00003598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003599 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600 : __shared_count(__refs),
3601 __shared_weak_owners_(__refs) {}
3602protected:
3603 virtual ~__shared_weak_count();
3604
3605public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003606 void __add_shared() _NOEXCEPT;
3607 void __add_weak() _NOEXCEPT;
3608 void __release_shared() _NOEXCEPT;
3609 void __release_weak() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003611 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3612 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613
Howard Hinnant9b763e02012-05-19 20:20:49 +00003614 // purposefully not protected with #ifndef _LIBCPP_NO_RTTI because doing so
3615 // breaks ABI for those clients who need to compile their projects with
3616 // -fno-rtti and yet link against a libc++.dylib compiled without -fno-rtti.
Howard Hinnant1694d232011-05-28 14:41:13 +00003617 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003618private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003619 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003620};
3621
3622template <class _Tp, class _Dp, class _Alloc>
3623class __shared_ptr_pointer
3624 : public __shared_weak_count
3625{
3626 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3627public:
Howard Hinnant82894812010-09-22 16:48:34 +00003628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003630 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631
Howard Hinnantd4444702010-08-11 17:04:31 +00003632#ifndef _LIBCPP_NO_RTTI
Howard Hinnant1694d232011-05-28 14:41:13 +00003633 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnantd4444702010-08-11 17:04:31 +00003634#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635
3636private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003637 virtual void __on_zero_shared() _NOEXCEPT;
3638 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003639};
3640
Howard Hinnantd4444702010-08-11 17:04:31 +00003641#ifndef _LIBCPP_NO_RTTI
3642
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003643template <class _Tp, class _Dp, class _Alloc>
3644const void*
Howard Hinnant1694d232011-05-28 14:41:13 +00003645__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003646{
3647 return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3648}
3649
Howard Hinnant324bb032010-08-22 00:02:43 +00003650#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00003651
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003652template <class _Tp, class _Dp, class _Alloc>
3653void
Howard Hinnant1694d232011-05-28 14:41:13 +00003654__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655{
3656 __data_.first().second()(__data_.first().first());
3657 __data_.first().second().~_Dp();
3658}
3659
3660template <class _Tp, class _Dp, class _Alloc>
3661void
Howard Hinnant1694d232011-05-28 14:41:13 +00003662__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003663{
3664 typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3665 __data_.second().~_Alloc();
3666 __a.deallocate(this, 1);
3667}
3668
3669template <class _Tp, class _Alloc>
3670class __shared_ptr_emplace
3671 : public __shared_weak_count
3672{
3673 __compressed_pair<_Alloc, _Tp> __data_;
3674public:
3675#ifndef _LIBCPP_HAS_NO_VARIADICS
3676
Howard Hinnant82894812010-09-22 16:48:34 +00003677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678 __shared_ptr_emplace(_Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003679 : __data_(_VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680
3681 template <class ..._Args>
Howard Hinnant82894812010-09-22 16:48:34 +00003682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00003684 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3685 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003686
3687#else // _LIBCPP_HAS_NO_VARIADICS
3688
Howard Hinnant82894812010-09-22 16:48:34 +00003689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690 __shared_ptr_emplace(_Alloc __a)
3691 : __data_(__a) {}
3692
3693 template <class _A0>
Howard Hinnant82894812010-09-22 16:48:34 +00003694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003695 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3696 : __data_(__a, _Tp(__a0)) {}
3697
3698 template <class _A0, class _A1>
Howard Hinnant82894812010-09-22 16:48:34 +00003699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3701 : __data_(__a, _Tp(__a0, __a1)) {}
3702
3703 template <class _A0, class _A1, class _A2>
Howard Hinnant82894812010-09-22 16:48:34 +00003704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3706 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3707
3708#endif // _LIBCPP_HAS_NO_VARIADICS
3709
3710private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003711 virtual void __on_zero_shared() _NOEXCEPT;
3712 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713public:
Howard Hinnant82894812010-09-22 16:48:34 +00003714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003715 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003716};
3717
3718template <class _Tp, class _Alloc>
3719void
Howard Hinnant1694d232011-05-28 14:41:13 +00003720__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003721{
3722 __data_.second().~_Tp();
3723}
3724
3725template <class _Tp, class _Alloc>
3726void
Howard Hinnant1694d232011-05-28 14:41:13 +00003727__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003728{
3729 typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3730 __data_.first().~_Alloc();
3731 __a.deallocate(this, 1);
3732}
3733
3734template<class _Tp> class enable_shared_from_this;
3735
3736template<class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00003737class _LIBCPP_VISIBLE shared_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003738{
Howard Hinnant324bb032010-08-22 00:02:43 +00003739public:
3740 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003741private:
3742 element_type* __ptr_;
3743 __shared_weak_count* __cntrl_;
3744
3745 struct __nat {int __for_bool_;};
3746public:
Howard Hinnant46e94932012-07-07 20:56:04 +00003747 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3748 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003749 template<class _Yp,
3750 class = typename enable_if
3751 <
3752 is_convertible<_Yp*, element_type*>::value
3753 >::type
3754 >
3755 explicit shared_ptr(_Yp* __p);
3756 template<class _Yp, class _Dp,
3757 class = typename enable_if
3758 <
3759 is_convertible<_Yp*, element_type*>::value
3760 >::type
3761 >
3762 shared_ptr(_Yp* __p, _Dp __d);
3763 template<class _Yp, class _Dp, class _Alloc,
3764 class = typename enable_if
3765 <
3766 is_convertible<_Yp*, element_type*>::value
3767 >::type
3768 >
3769 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003770 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3771 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Howard Hinnant1694d232011-05-28 14:41:13 +00003772 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3773 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003774 template<class _Yp>
3775 shared_ptr(const shared_ptr<_Yp>& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003776 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3777 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003778#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003779 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003780 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003781 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3782 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003783#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003784 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Howard Hinnant324bb032010-08-22 00:02:43 +00003785 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003786#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003787 template<class _Yp,
3788 class = typename enable_if
3789 <
3790 is_convertible<_Yp*, element_type*>::value
3791 >::type
3792 >
3793 shared_ptr(auto_ptr<_Yp>&& __r);
Howard Hinnant324bb032010-08-22 00:02:43 +00003794#else
Howard Hinnant57199402012-01-02 17:56:02 +00003795 template<class _Yp,
3796 class = typename enable_if
3797 <
3798 is_convertible<_Yp*, element_type*>::value
3799 >::type
3800 >
3801 shared_ptr(auto_ptr<_Yp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +00003803#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003804 template <class _Yp, class _Dp,
3805 class = typename enable_if
3806 <
3807 !is_array<_Yp>::value &&
3808 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3809 >::type
3810 >
3811 shared_ptr(unique_ptr<_Yp, _Dp>&&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003812 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
Howard Hinnant57199402012-01-02 17:56:02 +00003813 template <class _Yp, class _Dp,
3814 class = typename enable_if
3815 <
3816 !is_array<_Yp>::value &&
3817 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3818 >::type
3819 >
3820 shared_ptr(unique_ptr<_Yp, _Dp>&&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003821 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003822#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003823 template <class _Yp, class _Dp,
3824 class = typename enable_if
3825 <
3826 !is_array<_Yp>::value &&
3827 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3828 >::type
3829 > shared_ptr(unique_ptr<_Yp, _Dp>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
Howard Hinnant57199402012-01-02 17:56:02 +00003831 template <class _Yp, class _Dp,
3832 class = typename enable_if
3833 <
3834 !is_array<_Yp>::value &&
3835 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3836 >::type
3837 >
3838 shared_ptr(unique_ptr<_Yp, _Dp>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003839 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003840#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003841
3842 ~shared_ptr();
3843
Howard Hinnant1694d232011-05-28 14:41:13 +00003844 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003845 template<class _Yp>
3846 typename enable_if
3847 <
3848 is_convertible<_Yp*, element_type*>::value,
3849 shared_ptr&
3850 >::type
3851 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003852#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003853 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003854 template<class _Yp>
3855 typename enable_if
3856 <
3857 is_convertible<_Yp*, element_type*>::value,
3858 shared_ptr<_Tp>&
3859 >::type
3860 operator=(shared_ptr<_Yp>&& __r);
3861 template<class _Yp>
3862 typename enable_if
3863 <
3864 !is_array<_Yp>::value &&
3865 is_convertible<_Yp*, element_type*>::value,
3866 shared_ptr&
3867 >::type
3868 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003869#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003870 template<class _Yp>
3871 typename enable_if
3872 <
3873 !is_array<_Yp>::value &&
3874 is_convertible<_Yp*, element_type*>::value,
3875 shared_ptr&
3876 >::type
3877 operator=(auto_ptr<_Yp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878#endif
Howard Hinnant57199402012-01-02 17:56:02 +00003879 template <class _Yp, class _Dp>
3880 typename enable_if
3881 <
3882 !is_array<_Yp>::value &&
3883 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3884 shared_ptr&
3885 >::type
Howard Hinnant73d21a42010-09-04 23:28:19 +00003886#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003887 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003888#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003889 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890#endif
3891
Howard Hinnant1694d232011-05-28 14:41:13 +00003892 void swap(shared_ptr& __r) _NOEXCEPT;
3893 void reset() _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003894 template<class _Yp>
3895 typename enable_if
3896 <
3897 is_convertible<_Yp*, element_type*>::value,
3898 void
3899 >::type
3900 reset(_Yp* __p);
3901 template<class _Yp, class _Dp>
3902 typename enable_if
3903 <
3904 is_convertible<_Yp*, element_type*>::value,
3905 void
3906 >::type
3907 reset(_Yp* __p, _Dp __d);
3908 template<class _Yp, class _Dp, class _Alloc>
3909 typename enable_if
3910 <
3911 is_convertible<_Yp*, element_type*>::value,
3912 void
3913 >::type
3914 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915
Howard Hinnant82894812010-09-22 16:48:34 +00003916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003917 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003919 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3920 {return *__ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003922 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003924 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00003925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003926 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant82894812010-09-22 16:48:34 +00003927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00003928 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnant99968442011-11-29 18:15:50 +00003929 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003931 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003932 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant99968442011-11-29 18:15:50 +00003933 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003935 bool owner_before(weak_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003936 {return __cntrl_ < __p.__cntrl_;}
3937
Howard Hinnantd4444702010-08-11 17:04:31 +00003938#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939 template <class _Dp>
Howard Hinnant82894812010-09-22 16:48:34 +00003940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003941 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003942 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnant324bb032010-08-22 00:02:43 +00003943#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003944
3945#ifndef _LIBCPP_HAS_NO_VARIADICS
3946
3947 template<class ..._Args>
3948 static
3949 shared_ptr<_Tp>
3950 make_shared(_Args&& ...__args);
3951
3952 template<class _Alloc, class ..._Args>
3953 static
3954 shared_ptr<_Tp>
3955 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3956
3957#else // _LIBCPP_HAS_NO_VARIADICS
3958
3959 static shared_ptr<_Tp> make_shared();
3960
3961 template<class _A0>
3962 static shared_ptr<_Tp> make_shared(_A0&);
3963
3964 template<class _A0, class _A1>
3965 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3966
3967 template<class _A0, class _A1, class _A2>
3968 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3969
3970 template<class _Alloc>
3971 static shared_ptr<_Tp>
3972 allocate_shared(const _Alloc& __a);
3973
3974 template<class _Alloc, class _A0>
3975 static shared_ptr<_Tp>
3976 allocate_shared(const _Alloc& __a, _A0& __a0);
3977
3978 template<class _Alloc, class _A0, class _A1>
3979 static shared_ptr<_Tp>
3980 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3981
3982 template<class _Alloc, class _A0, class _A1, class _A2>
3983 static shared_ptr<_Tp>
3984 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3985
3986#endif // _LIBCPP_HAS_NO_VARIADICS
3987
3988private:
3989
3990 template <class _Yp>
Howard Hinnant82894812010-09-22 16:48:34 +00003991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003992 void
Howard Hinnant1694d232011-05-28 14:41:13 +00003993 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003994 {
3995 if (__e)
3996 __e->__weak_this_ = *this;
3997 }
3998
Howard Hinnant82894812010-09-22 16:48:34 +00003999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004000 void __enable_weak_this(const void*) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004001
Howard Hinnant82894812010-09-22 16:48:34 +00004002 template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
4003 template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004004};
4005
4006template<class _Tp>
4007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004008_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004009shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004010 : __ptr_(0),
4011 __cntrl_(0)
4012{
4013}
4014
4015template<class _Tp>
4016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004017_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004018shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004019 : __ptr_(0),
4020 __cntrl_(0)
4021{
4022}
4023
4024template<class _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00004025template<class _Yp, class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004026shared_ptr<_Tp>::shared_ptr(_Yp* __p)
4027 : __ptr_(__p)
4028{
4029 unique_ptr<_Yp> __hold(__p);
4030 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4031 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4032 __hold.release();
4033 __enable_weak_this(__p);
4034}
4035
4036template<class _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00004037template<class _Yp, class _Dp, class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004038shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4039 : __ptr_(__p)
4040{
4041#ifndef _LIBCPP_NO_EXCEPTIONS
4042 try
4043 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004044#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004045 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4046 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4047 __enable_weak_this(__p);
4048#ifndef _LIBCPP_NO_EXCEPTIONS
4049 }
4050 catch (...)
4051 {
4052 __d(__p);
4053 throw;
4054 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004055#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004056}
4057
4058template<class _Tp>
4059template<class _Dp>
4060shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4061 : __ptr_(0)
4062{
4063#ifndef _LIBCPP_NO_EXCEPTIONS
4064 try
4065 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004066#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004067 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4068 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4069#ifndef _LIBCPP_NO_EXCEPTIONS
4070 }
4071 catch (...)
4072 {
4073 __d(__p);
4074 throw;
4075 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004076#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004077}
4078
4079template<class _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00004080template<class _Yp, class _Dp, class _Alloc, class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004081shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4082 : __ptr_(__p)
4083{
4084#ifndef _LIBCPP_NO_EXCEPTIONS
4085 try
4086 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004087#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004088 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4089 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4090 typedef __allocator_destructor<_A2> _D2;
4091 _A2 __a2(__a);
4092 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4093 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4094 __cntrl_ = __hold2.release();
4095 __enable_weak_this(__p);
4096#ifndef _LIBCPP_NO_EXCEPTIONS
4097 }
4098 catch (...)
4099 {
4100 __d(__p);
4101 throw;
4102 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004103#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104}
4105
4106template<class _Tp>
4107template<class _Dp, class _Alloc>
4108shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4109 : __ptr_(0)
4110{
4111#ifndef _LIBCPP_NO_EXCEPTIONS
4112 try
4113 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004114#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004115 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4116 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4117 typedef __allocator_destructor<_A2> _D2;
4118 _A2 __a2(__a);
4119 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4120 ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4121 __cntrl_ = __hold2.release();
4122#ifndef _LIBCPP_NO_EXCEPTIONS
4123 }
4124 catch (...)
4125 {
4126 __d(__p);
4127 throw;
4128 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004129#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004130}
4131
4132template<class _Tp>
4133template<class _Yp>
4134inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004135shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004136 : __ptr_(__p),
4137 __cntrl_(__r.__cntrl_)
4138{
4139 if (__cntrl_)
4140 __cntrl_->__add_shared();
4141}
4142
4143template<class _Tp>
4144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004145shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004146 : __ptr_(__r.__ptr_),
4147 __cntrl_(__r.__cntrl_)
4148{
4149 if (__cntrl_)
4150 __cntrl_->__add_shared();
4151}
4152
4153template<class _Tp>
4154template<class _Yp>
4155inline _LIBCPP_INLINE_VISIBILITY
4156shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4157 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004158 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004159 : __ptr_(__r.__ptr_),
4160 __cntrl_(__r.__cntrl_)
4161{
4162 if (__cntrl_)
4163 __cntrl_->__add_shared();
4164}
4165
Howard Hinnant73d21a42010-09-04 23:28:19 +00004166#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004167
4168template<class _Tp>
4169inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004170shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004171 : __ptr_(__r.__ptr_),
4172 __cntrl_(__r.__cntrl_)
4173{
4174 __r.__ptr_ = 0;
4175 __r.__cntrl_ = 0;
4176}
4177
4178template<class _Tp>
4179template<class _Yp>
4180inline _LIBCPP_INLINE_VISIBILITY
4181shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4182 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004183 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004184 : __ptr_(__r.__ptr_),
4185 __cntrl_(__r.__cntrl_)
4186{
4187 __r.__ptr_ = 0;
4188 __r.__cntrl_ = 0;
4189}
4190
Howard Hinnant73d21a42010-09-04 23:28:19 +00004191#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004192
4193template<class _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00004194template<class _Yp, class>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004195#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004196shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4197#else
Howard Hinnant92172b82010-08-21 21:14:53 +00004198shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004199#endif
4200 : __ptr_(__r.get())
4201{
4202 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4203 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4204 __enable_weak_this(__r.get());
4205 __r.release();
4206}
4207
4208template<class _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00004209template <class _Yp, class _Dp, class>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004210#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004211shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4212#else
4213shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4214#endif
4215 typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4216 : __ptr_(__r.get())
4217{
4218 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4219 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4220 __enable_weak_this(__r.get());
4221 __r.release();
4222}
4223
4224template<class _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00004225template <class _Yp, class _Dp, class>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004226#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004227shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4228#else
4229shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4230#endif
4231 typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4232 : __ptr_(__r.get())
4233{
4234 typedef __shared_ptr_pointer<_Yp*,
4235 reference_wrapper<typename remove_reference<_Dp>::type>,
4236 allocator<_Yp> > _CntrlBlk;
4237 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4238 __enable_weak_this(__r.get());
4239 __r.release();
4240}
4241
4242#ifndef _LIBCPP_HAS_NO_VARIADICS
4243
4244template<class _Tp>
4245template<class ..._Args>
4246shared_ptr<_Tp>
4247shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4248{
4249 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4250 typedef allocator<_CntrlBlk> _A2;
4251 typedef __allocator_destructor<_A2> _D2;
4252 _A2 __a2;
4253 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00004254 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004255 shared_ptr<_Tp> __r;
4256 __r.__ptr_ = __hold2.get()->get();
4257 __r.__cntrl_ = __hold2.release();
4258 __r.__enable_weak_this(__r.__ptr_);
4259 return __r;
4260}
4261
4262template<class _Tp>
4263template<class _Alloc, class ..._Args>
4264shared_ptr<_Tp>
4265shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4266{
4267 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4268 typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4269 typedef __allocator_destructor<_A2> _D2;
4270 _A2 __a2(__a);
4271 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00004272 ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004273 shared_ptr<_Tp> __r;
4274 __r.__ptr_ = __hold2.get()->get();
4275 __r.__cntrl_ = __hold2.release();
4276 __r.__enable_weak_this(__r.__ptr_);
4277 return __r;
4278}
4279
4280#else // _LIBCPP_HAS_NO_VARIADICS
4281
4282template<class _Tp>
4283shared_ptr<_Tp>
4284shared_ptr<_Tp>::make_shared()
4285{
4286 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4287 typedef allocator<_CntrlBlk> _Alloc2;
4288 typedef __allocator_destructor<_Alloc2> _D2;
4289 _Alloc2 __alloc2;
4290 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4291 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4292 shared_ptr<_Tp> __r;
4293 __r.__ptr_ = __hold2.get()->get();
4294 __r.__cntrl_ = __hold2.release();
4295 __r.__enable_weak_this(__r.__ptr_);
4296 return __r;
4297}
4298
4299template<class _Tp>
4300template<class _A0>
4301shared_ptr<_Tp>
4302shared_ptr<_Tp>::make_shared(_A0& __a0)
4303{
4304 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4305 typedef allocator<_CntrlBlk> _Alloc2;
4306 typedef __allocator_destructor<_Alloc2> _D2;
4307 _Alloc2 __alloc2;
4308 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4309 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4310 shared_ptr<_Tp> __r;
4311 __r.__ptr_ = __hold2.get()->get();
4312 __r.__cntrl_ = __hold2.release();
4313 __r.__enable_weak_this(__r.__ptr_);
4314 return __r;
4315}
4316
4317template<class _Tp>
4318template<class _A0, class _A1>
4319shared_ptr<_Tp>
4320shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4321{
4322 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4323 typedef allocator<_CntrlBlk> _Alloc2;
4324 typedef __allocator_destructor<_Alloc2> _D2;
4325 _Alloc2 __alloc2;
4326 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4327 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4328 shared_ptr<_Tp> __r;
4329 __r.__ptr_ = __hold2.get()->get();
4330 __r.__cntrl_ = __hold2.release();
4331 __r.__enable_weak_this(__r.__ptr_);
4332 return __r;
4333}
4334
4335template<class _Tp>
4336template<class _A0, class _A1, class _A2>
4337shared_ptr<_Tp>
4338shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4339{
4340 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4341 typedef allocator<_CntrlBlk> _Alloc2;
4342 typedef __allocator_destructor<_Alloc2> _D2;
4343 _Alloc2 __alloc2;
4344 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4345 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4346 shared_ptr<_Tp> __r;
4347 __r.__ptr_ = __hold2.get()->get();
4348 __r.__cntrl_ = __hold2.release();
4349 __r.__enable_weak_this(__r.__ptr_);
4350 return __r;
4351}
4352
4353template<class _Tp>
4354template<class _Alloc>
4355shared_ptr<_Tp>
4356shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4357{
4358 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4359 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4360 typedef __allocator_destructor<_Alloc2> _D2;
4361 _Alloc2 __alloc2(__a);
4362 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4363 ::new(__hold2.get()) _CntrlBlk(__a);
4364 shared_ptr<_Tp> __r;
4365 __r.__ptr_ = __hold2.get()->get();
4366 __r.__cntrl_ = __hold2.release();
4367 __r.__enable_weak_this(__r.__ptr_);
4368 return __r;
4369}
4370
4371template<class _Tp>
4372template<class _Alloc, class _A0>
4373shared_ptr<_Tp>
4374shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4375{
4376 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4377 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4378 typedef __allocator_destructor<_Alloc2> _D2;
4379 _Alloc2 __alloc2(__a);
4380 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4381 ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4382 shared_ptr<_Tp> __r;
4383 __r.__ptr_ = __hold2.get()->get();
4384 __r.__cntrl_ = __hold2.release();
4385 __r.__enable_weak_this(__r.__ptr_);
4386 return __r;
4387}
4388
4389template<class _Tp>
4390template<class _Alloc, class _A0, class _A1>
4391shared_ptr<_Tp>
4392shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4393{
4394 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4395 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4396 typedef __allocator_destructor<_Alloc2> _D2;
4397 _Alloc2 __alloc2(__a);
4398 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4399 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4400 shared_ptr<_Tp> __r;
4401 __r.__ptr_ = __hold2.get()->get();
4402 __r.__cntrl_ = __hold2.release();
4403 __r.__enable_weak_this(__r.__ptr_);
4404 return __r;
4405}
4406
4407template<class _Tp>
4408template<class _Alloc, class _A0, class _A1, class _A2>
4409shared_ptr<_Tp>
4410shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4411{
4412 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4413 typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4414 typedef __allocator_destructor<_Alloc2> _D2;
4415 _Alloc2 __alloc2(__a);
4416 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4417 ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4418 shared_ptr<_Tp> __r;
4419 __r.__ptr_ = __hold2.get()->get();
4420 __r.__cntrl_ = __hold2.release();
4421 __r.__enable_weak_this(__r.__ptr_);
4422 return __r;
4423}
4424
4425#endif // _LIBCPP_HAS_NO_VARIADICS
4426
4427template<class _Tp>
4428shared_ptr<_Tp>::~shared_ptr()
4429{
4430 if (__cntrl_)
4431 __cntrl_->__release_shared();
4432}
4433
4434template<class _Tp>
4435inline _LIBCPP_INLINE_VISIBILITY
4436shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004437shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004438{
4439 shared_ptr(__r).swap(*this);
4440 return *this;
4441}
4442
4443template<class _Tp>
4444template<class _Yp>
4445inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004446typename enable_if
4447<
4448 is_convertible<_Yp*, _Tp*>::value,
4449 shared_ptr<_Tp>&
4450>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004451shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004452{
4453 shared_ptr(__r).swap(*this);
4454 return *this;
4455}
4456
Howard Hinnant73d21a42010-09-04 23:28:19 +00004457#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004458
4459template<class _Tp>
4460inline _LIBCPP_INLINE_VISIBILITY
4461shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004462shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004463{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004464 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004465 return *this;
4466}
4467
4468template<class _Tp>
4469template<class _Yp>
4470inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004471typename enable_if
4472<
4473 is_convertible<_Yp*, _Tp*>::value,
4474 shared_ptr<_Tp>&
4475>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004476shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4477{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004478 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004479 return *this;
4480}
4481
4482template<class _Tp>
4483template<class _Yp>
4484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004485typename enable_if
4486<
4487 !is_array<_Yp>::value &&
4488 is_convertible<_Yp*, _Tp*>::value,
4489 shared_ptr<_Tp>&
4490>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004491shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4492{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004493 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004494 return *this;
4495}
4496
4497template<class _Tp>
4498template <class _Yp, class _Dp>
4499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004500typename enable_if
4501<
4502 !is_array<_Yp>::value &&
4503 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4504 shared_ptr<_Tp>&
4505>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004506shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4507{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004508 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004509 return *this;
4510}
4511
Howard Hinnant73d21a42010-09-04 23:28:19 +00004512#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004513
4514template<class _Tp>
4515template<class _Yp>
4516inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004517typename enable_if
4518<
4519 !is_array<_Yp>::value &&
4520 is_convertible<_Yp*, _Tp*>::value,
4521 shared_ptr<_Tp>&
4522>::type
Howard Hinnant324bb032010-08-22 00:02:43 +00004523shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004524{
4525 shared_ptr(__r).swap(*this);
4526 return *this;
4527}
4528
4529template<class _Tp>
4530template <class _Yp, class _Dp>
4531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004532typename enable_if
4533<
4534 !is_array<_Yp>::value &&
4535 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4536 shared_ptr<_Tp>&
4537>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004538shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4539{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004540 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004541 return *this;
4542}
4543
Howard Hinnant73d21a42010-09-04 23:28:19 +00004544#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004545
4546template<class _Tp>
4547inline _LIBCPP_INLINE_VISIBILITY
4548void
Howard Hinnant1694d232011-05-28 14:41:13 +00004549shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004550{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004551 _VSTD::swap(__ptr_, __r.__ptr_);
4552 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004553}
4554
4555template<class _Tp>
4556inline _LIBCPP_INLINE_VISIBILITY
4557void
Howard Hinnant1694d232011-05-28 14:41:13 +00004558shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004559{
4560 shared_ptr().swap(*this);
4561}
4562
4563template<class _Tp>
4564template<class _Yp>
4565inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004566typename enable_if
4567<
4568 is_convertible<_Yp*, _Tp*>::value,
4569 void
4570>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004571shared_ptr<_Tp>::reset(_Yp* __p)
4572{
4573 shared_ptr(__p).swap(*this);
4574}
4575
4576template<class _Tp>
4577template<class _Yp, class _Dp>
4578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004579typename enable_if
4580<
4581 is_convertible<_Yp*, _Tp*>::value,
4582 void
4583>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004584shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4585{
4586 shared_ptr(__p, __d).swap(*this);
4587}
4588
4589template<class _Tp>
4590template<class _Yp, class _Dp, class _Alloc>
4591inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004592typename enable_if
4593<
4594 is_convertible<_Yp*, _Tp*>::value,
4595 void
4596>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004597shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4598{
4599 shared_ptr(__p, __d, __a).swap(*this);
4600}
4601
4602#ifndef _LIBCPP_HAS_NO_VARIADICS
4603
Howard Hinnant324bb032010-08-22 00:02:43 +00004604template<class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004605inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004606typename enable_if
4607<
4608 !is_array<_Tp>::value,
4609 shared_ptr<_Tp>
4610>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004611make_shared(_Args&& ...__args)
4612{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004613 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004614}
4615
Howard Hinnant324bb032010-08-22 00:02:43 +00004616template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004617inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004618typename enable_if
4619<
4620 !is_array<_Tp>::value,
4621 shared_ptr<_Tp>
4622>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004623allocate_shared(const _Alloc& __a, _Args&& ...__args)
4624{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004625 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004626}
4627
4628#else // _LIBCPP_HAS_NO_VARIADICS
4629
4630template<class _Tp>
4631inline _LIBCPP_INLINE_VISIBILITY
4632shared_ptr<_Tp>
4633make_shared()
4634{
4635 return shared_ptr<_Tp>::make_shared();
4636}
4637
4638template<class _Tp, class _A0>
4639inline _LIBCPP_INLINE_VISIBILITY
4640shared_ptr<_Tp>
4641make_shared(_A0& __a0)
4642{
4643 return shared_ptr<_Tp>::make_shared(__a0);
4644}
4645
4646template<class _Tp, class _A0, class _A1>
4647inline _LIBCPP_INLINE_VISIBILITY
4648shared_ptr<_Tp>
4649make_shared(_A0& __a0, _A1& __a1)
4650{
4651 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4652}
4653
Howard Hinnant324bb032010-08-22 00:02:43 +00004654template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004655inline _LIBCPP_INLINE_VISIBILITY
4656shared_ptr<_Tp>
4657make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4658{
4659 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4660}
4661
4662template<class _Tp, class _Alloc>
4663inline _LIBCPP_INLINE_VISIBILITY
4664shared_ptr<_Tp>
4665allocate_shared(const _Alloc& __a)
4666{
4667 return shared_ptr<_Tp>::allocate_shared(__a);
4668}
4669
4670template<class _Tp, class _Alloc, class _A0>
4671inline _LIBCPP_INLINE_VISIBILITY
4672shared_ptr<_Tp>
4673allocate_shared(const _Alloc& __a, _A0& __a0)
4674{
4675 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4676}
4677
4678template<class _Tp, class _Alloc, class _A0, class _A1>
4679inline _LIBCPP_INLINE_VISIBILITY
4680shared_ptr<_Tp>
4681allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4682{
4683 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4684}
4685
4686template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4687inline _LIBCPP_INLINE_VISIBILITY
4688shared_ptr<_Tp>
4689allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4690{
4691 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4692}
4693
4694#endif // _LIBCPP_HAS_NO_VARIADICS
4695
4696template<class _Tp, class _Up>
4697inline _LIBCPP_INLINE_VISIBILITY
4698bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004699operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004700{
4701 return __x.get() == __y.get();
4702}
4703
4704template<class _Tp, class _Up>
4705inline _LIBCPP_INLINE_VISIBILITY
4706bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004707operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004708{
4709 return !(__x == __y);
4710}
4711
4712template<class _Tp, class _Up>
4713inline _LIBCPP_INLINE_VISIBILITY
4714bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004715operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004716{
Howard Hinnant3fadda32012-02-21 21:02:58 +00004717 typedef typename common_type<_Tp*, _Up*>::type _V;
4718 return less<_V>()(__x.get(), __y.get());
4719}
4720
4721template<class _Tp, class _Up>
4722inline _LIBCPP_INLINE_VISIBILITY
4723bool
4724operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4725{
4726 return __y < __x;
4727}
4728
4729template<class _Tp, class _Up>
4730inline _LIBCPP_INLINE_VISIBILITY
4731bool
4732operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4733{
4734 return !(__y < __x);
4735}
4736
4737template<class _Tp, class _Up>
4738inline _LIBCPP_INLINE_VISIBILITY
4739bool
4740operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4741{
4742 return !(__x < __y);
4743}
4744
4745template<class _Tp>
4746inline _LIBCPP_INLINE_VISIBILITY
4747bool
4748operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4749{
4750 return !__x;
4751}
4752
4753template<class _Tp>
4754inline _LIBCPP_INLINE_VISIBILITY
4755bool
4756operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4757{
4758 return !__x;
4759}
4760
4761template<class _Tp>
4762inline _LIBCPP_INLINE_VISIBILITY
4763bool
4764operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4765{
4766 return static_cast<bool>(__x);
4767}
4768
4769template<class _Tp>
4770inline _LIBCPP_INLINE_VISIBILITY
4771bool
4772operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4773{
4774 return static_cast<bool>(__x);
4775}
4776
4777template<class _Tp>
4778inline _LIBCPP_INLINE_VISIBILITY
4779bool
4780operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4781{
4782 return less<_Tp*>()(__x.get(), nullptr);
4783}
4784
4785template<class _Tp>
4786inline _LIBCPP_INLINE_VISIBILITY
4787bool
4788operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4789{
4790 return less<_Tp*>()(nullptr, __x.get());
4791}
4792
4793template<class _Tp>
4794inline _LIBCPP_INLINE_VISIBILITY
4795bool
4796operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4797{
4798 return nullptr < __x;
4799}
4800
4801template<class _Tp>
4802inline _LIBCPP_INLINE_VISIBILITY
4803bool
4804operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4805{
4806 return __x < nullptr;
4807}
4808
4809template<class _Tp>
4810inline _LIBCPP_INLINE_VISIBILITY
4811bool
4812operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4813{
4814 return !(nullptr < __x);
4815}
4816
4817template<class _Tp>
4818inline _LIBCPP_INLINE_VISIBILITY
4819bool
4820operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4821{
4822 return !(__x < nullptr);
4823}
4824
4825template<class _Tp>
4826inline _LIBCPP_INLINE_VISIBILITY
4827bool
4828operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4829{
4830 return !(__x < nullptr);
4831}
4832
4833template<class _Tp>
4834inline _LIBCPP_INLINE_VISIBILITY
4835bool
4836operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4837{
4838 return !(nullptr < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004839}
4840
4841template<class _Tp>
4842inline _LIBCPP_INLINE_VISIBILITY
4843void
Howard Hinnant1694d232011-05-28 14:41:13 +00004844swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004845{
4846 __x.swap(__y);
4847}
4848
4849template<class _Tp, class _Up>
4850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004851typename enable_if
4852<
4853 !is_array<_Tp>::value && !is_array<_Up>::value,
4854 shared_ptr<_Tp>
4855>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004856static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004857{
4858 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4859}
4860
4861template<class _Tp, class _Up>
4862inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004863typename enable_if
4864<
4865 !is_array<_Tp>::value && !is_array<_Up>::value,
4866 shared_ptr<_Tp>
4867>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004868dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004869{
4870 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4871 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4872}
4873
4874template<class _Tp, class _Up>
Howard Hinnant57199402012-01-02 17:56:02 +00004875typename enable_if
4876<
4877 is_array<_Tp>::value == is_array<_Up>::value,
4878 shared_ptr<_Tp>
4879>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004880const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004881{
Howard Hinnant57199402012-01-02 17:56:02 +00004882 typedef typename remove_extent<_Tp>::type _RTp;
4883 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004884}
4885
Howard Hinnantd4444702010-08-11 17:04:31 +00004886#ifndef _LIBCPP_NO_RTTI
4887
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004888template<class _Dp, class _Tp>
4889inline _LIBCPP_INLINE_VISIBILITY
4890_Dp*
Howard Hinnant1694d232011-05-28 14:41:13 +00004891get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004892{
4893 return __p.template __get_deleter<_Dp>();
4894}
4895
Howard Hinnant324bb032010-08-22 00:02:43 +00004896#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00004897
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004898template<class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00004899class _LIBCPP_VISIBLE weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004900{
Howard Hinnant324bb032010-08-22 00:02:43 +00004901public:
4902 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004903private:
4904 element_type* __ptr_;
4905 __shared_weak_count* __cntrl_;
4906
Howard Hinnant324bb032010-08-22 00:02:43 +00004907public:
Howard Hinnant46e94932012-07-07 20:56:04 +00004908 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004909 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00004910 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4911 _NOEXCEPT;
4912 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004913 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00004914 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4915 _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00004916
Howard Hinnant57199402012-01-02 17:56:02 +00004917#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4918 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4919 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4920 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4921 _NOEXCEPT;
4922#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant324bb032010-08-22 00:02:43 +00004923 ~weak_ptr();
4924
Howard Hinnant1694d232011-05-28 14:41:13 +00004925 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00004926 template<class _Yp>
4927 typename enable_if
4928 <
4929 is_convertible<_Yp*, element_type*>::value,
4930 weak_ptr&
4931 >::type
4932 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4933
4934#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4935
4936 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4937 template<class _Yp>
4938 typename enable_if
4939 <
4940 is_convertible<_Yp*, element_type*>::value,
4941 weak_ptr&
4942 >::type
4943 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4944
4945#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4946
4947 template<class _Yp>
4948 typename enable_if
4949 <
4950 is_convertible<_Yp*, element_type*>::value,
4951 weak_ptr&
4952 >::type
4953 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00004954
Howard Hinnant1694d232011-05-28 14:41:13 +00004955 void swap(weak_ptr& __r) _NOEXCEPT;
4956 void reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00004957
Howard Hinnant82894812010-09-22 16:48:34 +00004958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004959 long use_count() const _NOEXCEPT
4960 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00004961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004962 bool expired() const _NOEXCEPT
4963 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4964 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00004965 template<class _Up>
4966 _LIBCPP_INLINE_VISIBILITY
4967 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004968 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant82894812010-09-22 16:48:34 +00004969 template<class _Up>
4970 _LIBCPP_INLINE_VISIBILITY
4971 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004972 {return __cntrl_ < __r.__cntrl_;}
4973
Howard Hinnant82894812010-09-22 16:48:34 +00004974 template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
4975 template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004976};
4977
4978template<class _Tp>
4979inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004980_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004981weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004982 : __ptr_(0),
4983 __cntrl_(0)
4984{
4985}
4986
4987template<class _Tp>
4988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004989weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004990 : __ptr_(__r.__ptr_),
4991 __cntrl_(__r.__cntrl_)
4992{
4993 if (__cntrl_)
4994 __cntrl_->__add_weak();
4995}
4996
4997template<class _Tp>
4998template<class _Yp>
4999inline _LIBCPP_INLINE_VISIBILITY
5000weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005001 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005002 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005003 : __ptr_(__r.__ptr_),
5004 __cntrl_(__r.__cntrl_)
5005{
5006 if (__cntrl_)
5007 __cntrl_->__add_weak();
5008}
5009
5010template<class _Tp>
5011template<class _Yp>
5012inline _LIBCPP_INLINE_VISIBILITY
5013weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005014 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005015 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005016 : __ptr_(__r.__ptr_),
5017 __cntrl_(__r.__cntrl_)
5018{
5019 if (__cntrl_)
5020 __cntrl_->__add_weak();
5021}
5022
Howard Hinnant57199402012-01-02 17:56:02 +00005023#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5024
5025template<class _Tp>
5026inline _LIBCPP_INLINE_VISIBILITY
5027weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5028 : __ptr_(__r.__ptr_),
5029 __cntrl_(__r.__cntrl_)
5030{
5031 __r.__ptr_ = 0;
5032 __r.__cntrl_ = 0;
5033}
5034
5035template<class _Tp>
5036template<class _Yp>
5037inline _LIBCPP_INLINE_VISIBILITY
5038weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5039 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5040 _NOEXCEPT
5041 : __ptr_(__r.__ptr_),
5042 __cntrl_(__r.__cntrl_)
5043{
5044 __r.__ptr_ = 0;
5045 __r.__cntrl_ = 0;
5046}
5047
5048#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5049
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005050template<class _Tp>
5051weak_ptr<_Tp>::~weak_ptr()
5052{
5053 if (__cntrl_)
5054 __cntrl_->__release_weak();
5055}
5056
5057template<class _Tp>
5058inline _LIBCPP_INLINE_VISIBILITY
5059weak_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00005060weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005061{
5062 weak_ptr(__r).swap(*this);
5063 return *this;
5064}
5065
5066template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005067template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005069typename enable_if
5070<
5071 is_convertible<_Yp*, _Tp*>::value,
5072 weak_ptr<_Tp>&
5073>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005074weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005075{
5076 weak_ptr(__r).swap(*this);
5077 return *this;
5078}
5079
Howard Hinnant57199402012-01-02 17:56:02 +00005080#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5081
5082template<class _Tp>
5083inline _LIBCPP_INLINE_VISIBILITY
5084weak_ptr<_Tp>&
5085weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5086{
5087 weak_ptr(_VSTD::move(__r)).swap(*this);
5088 return *this;
5089}
5090
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005091template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005092template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005094typename enable_if
5095<
5096 is_convertible<_Yp*, _Tp*>::value,
5097 weak_ptr<_Tp>&
5098>::type
5099weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5100{
5101 weak_ptr(_VSTD::move(__r)).swap(*this);
5102 return *this;
5103}
5104
5105#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5106
5107template<class _Tp>
5108template<class _Yp>
5109inline _LIBCPP_INLINE_VISIBILITY
5110typename enable_if
5111<
5112 is_convertible<_Yp*, _Tp*>::value,
5113 weak_ptr<_Tp>&
5114>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005115weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005116{
5117 weak_ptr(__r).swap(*this);
5118 return *this;
5119}
5120
5121template<class _Tp>
5122inline _LIBCPP_INLINE_VISIBILITY
5123void
Howard Hinnant1694d232011-05-28 14:41:13 +00005124weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005125{
Howard Hinnant0949eed2011-06-30 21:18:19 +00005126 _VSTD::swap(__ptr_, __r.__ptr_);
5127 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005128}
5129
5130template<class _Tp>
5131inline _LIBCPP_INLINE_VISIBILITY
5132void
Howard Hinnant1694d232011-05-28 14:41:13 +00005133swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005134{
5135 __x.swap(__y);
5136}
5137
5138template<class _Tp>
5139inline _LIBCPP_INLINE_VISIBILITY
5140void
Howard Hinnant1694d232011-05-28 14:41:13 +00005141weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005142{
5143 weak_ptr().swap(*this);
5144}
5145
5146template<class _Tp>
5147template<class _Yp>
5148shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5149 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5150 : __ptr_(__r.__ptr_),
5151 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5152{
5153 if (__cntrl_ == 0)
5154#ifndef _LIBCPP_NO_EXCEPTIONS
5155 throw bad_weak_ptr();
5156#else
5157 assert(!"bad_weak_ptr");
5158#endif
5159}
5160
5161template<class _Tp>
5162shared_ptr<_Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00005163weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005164{
5165 shared_ptr<_Tp> __r;
5166 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5167 if (__r.__cntrl_)
5168 __r.__ptr_ = __ptr_;
5169 return __r;
5170}
5171
Howard Hinnant324bb032010-08-22 00:02:43 +00005172template <class _Tp> struct owner_less;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005173
5174template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00005175struct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005176 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant324bb032010-08-22 00:02:43 +00005177{
5178 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005179 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005180 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5181 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005183 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5184 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005186 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5187 {return __x.owner_before(__y);}
Howard Hinnant324bb032010-08-22 00:02:43 +00005188};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005189
5190template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00005191struct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005192 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5193{
Howard Hinnant324bb032010-08-22 00:02:43 +00005194 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005196 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5197 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005199 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5200 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005202 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5203 {return __x.owner_before(__y);}
5204};
5205
5206template<class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00005207class _LIBCPP_VISIBLE enable_shared_from_this
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005208{
5209 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant324bb032010-08-22 00:02:43 +00005210protected:
Howard Hinnant46e94932012-07-07 20:56:04 +00005211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005212 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005214 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005216 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5217 {return *this;}
Howard Hinnant82894812010-09-22 16:48:34 +00005218 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005219 ~enable_shared_from_this() {}
Howard Hinnant324bb032010-08-22 00:02:43 +00005220public:
Howard Hinnant82894812010-09-22 16:48:34 +00005221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005222 shared_ptr<_Tp> shared_from_this()
5223 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant82894812010-09-22 16:48:34 +00005224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005225 shared_ptr<_Tp const> shared_from_this() const
5226 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005227
5228 template <class _Up> friend class shared_ptr;
5229};
5230
Howard Hinnant21aefc32010-06-03 16:42:57 +00005231template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00005232struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00005233{
5234 typedef shared_ptr<_Tp> argument_type;
5235 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005237 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00005238 {
5239 return hash<_Tp*>()(__ptr.get());
5240 }
5241};
5242
Howard Hinnant99968442011-11-29 18:15:50 +00005243template<class _CharT, class _Traits, class _Yp>
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005244inline _LIBCPP_INLINE_VISIBILITY
5245basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00005246operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005247
Howard Hinnant324bb032010-08-22 00:02:43 +00005248//enum class
Howard Hinnant82894812010-09-22 16:48:34 +00005249struct _LIBCPP_VISIBLE pointer_safety
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005250{
5251 enum _
5252 {
5253 relaxed,
5254 preferred,
5255 strict
5256 };
5257
5258 _ __v_;
5259
Howard Hinnant82894812010-09-22 16:48:34 +00005260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005261 pointer_safety(_ __v) : __v_(__v) {}
Howard Hinnant82894812010-09-22 16:48:34 +00005262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005263 operator int() const {return __v_;}
5264};
5265
5266void declare_reachable(void* __p);
5267void declare_no_pointers(char* __p, size_t __n);
5268void undeclare_no_pointers(char* __p, size_t __n);
Howard Hinnant1694d232011-05-28 14:41:13 +00005269pointer_safety get_pointer_safety() _NOEXCEPT;
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00005270void* __undeclare_reachable(void* __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005271
5272template <class _Tp>
5273inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00005274_Tp*
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005275undeclare_reachable(_Tp* __p)
5276{
5277 return static_cast<_Tp*>(__undeclare_reachable(__p));
5278}
5279
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00005280void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005281
5282_LIBCPP_END_NAMESPACE_STD
5283
5284#endif // _LIBCPP_MEMORY