libcxx initial import
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/memory b/include/memory
new file mode 100644
index 0000000..663c470
--- /dev/null
+++ b/include/memory
@@ -0,0 +1,3824 @@
+// -*- C++ -*-
+//===-------------------------- memory ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_MEMORY
+#define _LIBCPP_MEMORY
+
+/*
+ memory synopsis
+
+namespace std
+{
+
+struct allocator_arg_t { };
+constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+
+template <class T, class Alloc> struct uses_allocator;
+
+template <class Ptr>
+struct pointer_traits
+{
+ typedef Ptr pointer;
+ typedef <details> element_type;
+ typedef <details> difference_type;
+
+ template <class U> using rebind = <details>;
+
+ static pointer pointer_to(<details>);
+};
+
+template <class Alloc>
+struct allocator_traits
+{
+ typedef Alloc allocator_type;
+ typedef typename allocator_type::value_type
+ value_type;
+
+ typedef Alloc::pointer | value_type* pointer;
+ typedef Alloc::const_pointer
+ | pointer_traits<pointer>::rebind<const value_type>
+ const_pointer;
+ typedef Alloc::void_pointer
+ | pointer_traits<pointer>::rebind<void>
+ void_pointer;
+ typedef Alloc::const_void_pointer
+ | pointer_traits<pointer>::rebind<const void>
+ const_void_pointer;
+ typedef Alloc::difference_type
+ | ptrdiff_t difference_type;
+ typedef Alloc::size_type | size_t size_type;
+ typedef Alloc::propagate_on_container_copy_assignment
+ | false_type propagate_on_container_copy_assignment;
+ typedef Alloc::propagate_on_container_move_assignment
+ | false_type propagate_on_container_move_assignment;
+ typedef Alloc::propagate_on_container_swap
+ | false_type propagate_on_container_swap;
+
+ template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
+ template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
+
+ static pointer allocate(allocator_type& a, size_type n);
+ static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
+
+ static void deallocate(allocator_type& a, pointer p, size_type n);
+
+ template <class T, class... Args>
+ static void construct(allocator_type& a, T* p, Args&&... args);
+
+ template <class T>
+ static void destroy(allocator_type& a, T* p);
+
+ static size_type max_size(const allocator_type& a);
+
+ static allocator_type
+ select_on_container_copy_construction(const allocator_type& a);
+};
+
+template <>
+class allocator<void>
+{
+public:
+ typedef void* pointer;
+ typedef const void* const_pointer;
+ typedef void value_type;
+
+ template <class _Up> struct rebind {typedef allocator<_Up> other;};
+};
+
+template <class T>
+class allocator
+{
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef typename add_lvalue_reference<T>::type reference;
+ typedef typename add_lvalue_reference<const T>::type const_reference;
+ typedef T value_type;
+
+ template <class U> struct rebind {typedef allocator<U> other;};
+
+ allocator() throw();
+ allocator(const allocator&) throw();
+ template <class U> allocator(const allocator<U>&) throw();
+ ~allocator() throw();
+ pointer address(reference x) const;
+ const_pointer address(const_reference x) const;
+ pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
+ void deallocate(pointer p, size_type n);
+ size_type max_size() const throw();
+ void construct(pointer p, const T& val);
+ void destroy(pointer p);
+};
+
+template <class T, class U>
+bool operator==(const allocator<T>&, const allocator<U>&) throw();
+
+template <class T, class U>
+bool operator!=(const allocator<T>&, const allocator<U>&) throw();
+
+template <class OutputIterator, class T>
+class raw_storage_iterator
+ : public iterator<output_iterator_tag,
+ T, // purposefully not C++03
+ ptrdiff_t, // purposefully not C++03
+ T*, // purposefully not C++03
+ raw_storage_iterator&> // purposefully not C++03
+{
+public:
+ explicit raw_storage_iterator(OutputIterator x);
+ raw_storage_iterator& operator*();
+ raw_storage_iterator& operator=(const T& element);
+ raw_storage_iterator& operator++();
+ raw_storage_iterator operator++(int);
+};
+
+template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n);
+template <class T> void return_temporary_buffer(T* p);
+
+template <class InputIterator, class ForwardIterator>
+ForwardIterator
+uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
+
+template <class ForwardIterator, class T>
+void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
+
+template <class ForwardIterator, class Size, class T>
+void uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
+
+template <class Y> struct auto_ptr_ref {};
+
+template<class X>
+class auto_ptr
+{
+public:
+ typedef X element_type;
+
+ explicit auto_ptr(X* p =0) throw();
+ auto_ptr(auto_ptr&) throw();
+ template<class Y> auto_ptr(auto_ptr<Y>&) throw();
+ auto_ptr& operator=(auto_ptr&) throw();
+ template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
+ auto_ptr& operator=(auto_ptr_ref<X> r) throw();
+ ~auto_ptr() throw();
+
+ typename add_lvalue_reference<X>::type operator*() const throw();
+ X* operator->() const throw();
+ X* get() const throw();
+ X* release() throw();
+ void reset(X* p =0) throw();
+
+ auto_ptr(auto_ptr_ref<X>) throw();
+ template<class Y> operator auto_ptr_ref<Y>() throw();
+ template<class Y> operator auto_ptr<Y>() throw();
+};
+
+void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
+
+} // std
+
+*/
+
+#include <__config>
+#include <type_traits>
+#include <typeinfo>
+#include <cstddef>
+#include <cstdint>
+#include <new>
+#include <utility>
+#include <limits>
+#include <iterator>
+#include <__functional_base>
+#if defined(_LIBCPP_NO_EXCEPTIONS)
+ #include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// allocator_arg_t
+
+struct allocator_arg_t { };
+
+extern const allocator_arg_t allocator_arg;
+
+// addressof
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+addressof(_Tp& __x)
+{
+ return (_Tp*)&(char&)__x;
+}
+
+template <class _Tp> class allocator;
+
+template <>
+class allocator<void>
+{
+public:
+ typedef void* pointer;
+ typedef const void* const_pointer;
+ typedef void value_type;
+
+ template <class _Up> struct rebind {typedef allocator<_Up> other;};
+};
+
+
+// pointer_traits
+
+template <class _Tp>
+struct __has_element_type
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::element_type* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, bool = __has_element_type<_Ptr>::value>
+struct __pointer_traits_element_type;
+
+template <class _Ptr>
+struct __pointer_traits_element_type<_Ptr, true>
+{
+ typedef typename _Ptr::element_type type;
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args>
+struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
+{
+ typedef typename _Sp<_Tp, _Args...>::element_type type;
+};
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args>
+struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
+{
+ typedef _Tp type;
+};
+
+#else
+
+template <template <class> class _Sp, class _Tp>
+struct __pointer_traits_element_type<_Sp<_Tp>, true>
+{
+ typedef typename _Sp<_Tp>::element_type type;
+};
+
+template <template <class> class _Sp, class _Tp>
+struct __pointer_traits_element_type<_Sp<_Tp>, false>
+{
+ typedef _Tp type;
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
+{
+ typedef typename _Sp<_Tp, _A0>::element_type type;
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
+{
+ typedef _Tp type;
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
+{
+ typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
+{
+ typedef _Tp type;
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+ class _A1, class _A2>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
+{
+ typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+ class _A1, class _A2>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
+{
+ typedef _Tp type;
+};
+
+#endif
+
+template <class _Tp>
+struct __has_difference_type
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::difference_type* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
+struct __pointer_traits_difference_type
+{
+ typedef ptrdiff_t type;
+};
+
+template <class _Ptr>
+struct __pointer_traits_difference_type<_Ptr, true>
+{
+ typedef typename _Ptr::difference_type type;
+};
+
+template <class _Tp, class _Up>
+struct __has_rebind
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Xp> static __two __test(...);
+ template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
+struct __pointer_traits_rebind
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename _Tp::template rebind<_Up> type;
+#else
+ typedef typename _Tp::template rebind<_Up>::other type;
+#endif
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
+#else
+ typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
+{
+ typedef _Sp<_Up, _Args...> type;
+};
+
+#else
+
+template <template <class> class _Sp, class _Tp, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename _Sp<_Tp>::template rebind<_Up> type;
+#else
+ typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class> class _Sp, class _Tp, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
+{
+ typedef _Sp<_Up> type;
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
+#else
+ typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
+{
+ typedef _Sp<_Up, _A0> type;
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0,
+ class _A1, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
+#else
+ typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0,
+ class _A1, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
+{
+ typedef _Sp<_Up, _A0, _A1> type;
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+ class _A1, class _A2, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
+#else
+ typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+ class _A1, class _A2, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
+{
+ typedef _Sp<_Up, _A0, _A1, _A2> type;
+};
+
+#endif
+
+template <class _Ptr>
+struct pointer_traits
+{
+ typedef _Ptr pointer;
+ typedef typename __pointer_traits_element_type<pointer>::type element_type;
+ typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
+
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ template <class _Up> using rebind = __pointer_traits_rebind<pointer, _Up>::type;
+#else
+ template <class _Up> struct rebind
+ {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
+#endif
+
+private:
+ struct __nat {};
+public:
+ static pointer pointer_to(typename conditional<is_void<element_type>::value,
+ __nat, element_type>::type& __r)
+ {return pointer::pointer_to(__r);}
+};
+
+template <class _Tp>
+struct pointer_traits<_Tp*>
+{
+ typedef _Tp* pointer;
+ typedef _Tp element_type;
+ typedef ptrdiff_t difference_type;
+
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ template <class _Up> using rebind = _Up*;
+#else
+ template <class _Up> struct rebind {typedef _Up* other;};
+#endif
+
+private:
+ struct __nat {};
+public:
+ static pointer pointer_to(typename conditional<is_void<element_type>::value,
+ __nat, element_type>::type& __r)
+ {return _STD::addressof(__r);}
+};
+
+// allocator_traits
+
+namespace __has_pointer_type_imp
+{
+ template <class _Up> static __two test(...);
+ template <class _Up> static char test(typename _Up::pointer* = 0);
+}
+
+template <class _Tp>
+struct __has_pointer_type
+ : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
+{
+};
+
+namespace __pointer_type_imp
+{
+
+template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
+struct __pointer_type
+{
+ typedef typename _Dp::pointer type;
+};
+
+template <class _Tp, class _Dp>
+struct __pointer_type<_Tp, _Dp, false>
+{
+ typedef _Tp* type;
+};
+
+}
+
+template <class _Tp, class _Dp>
+struct __pointer_type
+{
+ typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
+};
+
+template <class _Tp>
+struct __has_const_pointer
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::const_pointer* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
+struct __const_pointer
+{
+ typedef typename _Alloc::const_pointer type;
+};
+
+template <class _Tp, class _Ptr, class _Alloc>
+struct __const_pointer<_Tp, _Ptr, _Alloc, false>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
+#else
+ typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
+#endif
+};
+
+template <class _Tp>
+struct __has_void_pointer
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::void_pointer* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
+struct __void_pointer
+{
+ typedef typename _Alloc::void_pointer type;
+};
+
+template <class _Ptr, class _Alloc>
+struct __void_pointer<_Ptr, _Alloc, false>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename pointer_traits<_Ptr>::template rebind<void> type;
+#else
+ typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
+#endif
+};
+
+template <class _Tp>
+struct __has_const_void_pointer
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
+struct __const_void_pointer
+{
+ typedef typename _Alloc::const_void_pointer type;
+};
+
+template <class _Ptr, class _Alloc>
+struct __const_void_pointer<_Ptr, _Alloc, false>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
+#else
+ typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
+#endif
+};
+
+template <class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+_T*
+__to_raw_pointer(_T* __p)
+{
+ return __p;
+}
+
+template <class _Pointer>
+inline _LIBCPP_INLINE_VISIBILITY
+typename pointer_traits<_Pointer>::element_type*
+__to_raw_pointer(_Pointer __p)
+{
+ return _STD::__to_raw_pointer(__p.operator->());
+}
+
+template <class _Tp>
+struct __has_size_type
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::size_type* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_size_type<_Alloc>::value>
+struct __size_type
+{
+ typedef size_t type;
+};
+
+template <class _Alloc>
+struct __size_type<_Alloc, true>
+{
+ typedef typename _Alloc::size_type type;
+};
+
+template <class _Tp>
+struct __has_propagate_on_container_copy_assignment
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
+struct __propagate_on_container_copy_assignment
+{
+ typedef false_type type;
+};
+
+template <class _Alloc>
+struct __propagate_on_container_copy_assignment<_Alloc, true>
+{
+ typedef typename _Alloc::propagate_on_container_copy_assignment type;
+};
+
+template <class _Tp>
+struct __has_propagate_on_container_move_assignment
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
+struct __propagate_on_container_move_assignment
+{
+ typedef false_type type;
+};
+
+template <class _Alloc>
+struct __propagate_on_container_move_assignment<_Alloc, true>
+{
+ typedef typename _Alloc::propagate_on_container_move_assignment type;
+};
+
+template <class _Tp>
+struct __has_propagate_on_container_swap
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
+struct __propagate_on_container_swap
+{
+ typedef false_type type;
+};
+
+template <class _Alloc>
+struct __propagate_on_container_swap<_Alloc, true>
+{
+ typedef typename _Alloc::propagate_on_container_swap type;
+};
+
+template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
+struct __has_rebind_other
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Xp> static __two __test(...);
+ template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Up>
+struct __has_rebind_other<_Tp, _Up, false>
+{
+ static const bool value = false;
+};
+
+template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
+struct __allocator_traits_rebind
+{
+ typedef typename _Tp::template rebind<_Up>::other type;
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
+{
+ typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
+};
+
+template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
+{
+ typedef _Alloc<_Up, _Args...> type;
+};
+
+#else
+
+template <template <class> class _Alloc, class _Tp, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
+{
+ typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
+};
+
+template <template <class> class _Alloc, class _Tp, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
+{
+ typedef _Alloc<_Up> type;
+};
+
+
+template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
+{
+ typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
+};
+
+template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
+{
+ typedef _Alloc<_Up, _A0> type;
+};
+
+
+template <template <class, class, class> class _Alloc, class _Tp, class _A0,
+ class _A1, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
+{
+ typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
+};
+
+template <template <class, class, class> class _Alloc, class _Tp, class _A0,
+ class _A1, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
+{
+ typedef _Alloc<_Up, _A0, _A1> type;
+};
+
+
+template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
+ class _A1, class _A2, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
+{
+ typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
+};
+
+template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
+ class _A1, class _A2, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
+{
+ typedef _Alloc<_Up, _A0, _A1, _A2> type;
+};
+
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+auto
+__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
+ -> decltype(__a.allocate(__sz, __p), true_type());
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+auto
+__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
+ -> false_type;
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+struct __has_allocate_hint
+ : integral_constant<bool,
+ is_same<
+ decltype(__has_allocate_hint_test(declval<_Alloc>(),
+ declval<_SizeType>(),
+ declval<_ConstVoidPtr>())),
+ true_type>::value>
+{
+};
+
+#else
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+struct __has_allocate_hint
+ : true_type
+{
+};
+
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+template <class _Alloc, class _Tp, class ..._Args>
+decltype(_STD::declval<_Alloc>().construct(_STD::declval<_Tp*>(),
+ _STD::declval<_Args>()...),
+ true_type())
+__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
+
+template <class _Alloc, class _Pointer, class ..._Args>
+false_type
+__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
+
+template <class _Alloc, class _Pointer, class ..._Args>
+struct __has_construct
+ : integral_constant<bool,
+ is_same<
+ decltype(__has_construct_test(declval<_Alloc>(),
+ declval<_Pointer>(),
+ declval<_Args>()...)),
+ true_type>::value>
+{
+};
+
+template <class _Alloc, class _Pointer>
+auto
+__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
+ -> decltype(__a.destroy(__p), true_type());
+
+template <class _Alloc, class _Pointer>
+auto
+__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
+ -> false_type;
+
+template <class _Alloc, class _Pointer>
+struct __has_destroy
+ : integral_constant<bool,
+ is_same<
+ decltype(__has_destroy_test(declval<_Alloc>(),
+ declval<_Pointer>())),
+ true_type>::value>
+{
+};
+
+template <class _Alloc>
+auto
+__has_max_size_test(_Alloc&& __a)
+ -> decltype(__a.max_size(), true_type());
+
+template <class _Alloc>
+auto
+__has_max_size_test(const volatile _Alloc& __a)
+ -> false_type;
+
+template <class _Alloc>
+struct __has_max_size
+ : integral_constant<bool,
+ is_same<
+ decltype(__has_max_size_test(declval<_Alloc&>())),
+ true_type>::value>
+{
+};
+
+template <class _Alloc>
+auto
+__has_select_on_container_copy_construction_test(_Alloc&& __a)
+ -> decltype(__a.select_on_container_copy_construction(), true_type());
+
+template <class _Alloc>
+auto
+__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
+ -> false_type;
+
+template <class _Alloc>
+struct __has_select_on_container_copy_construction
+ : integral_constant<bool,
+ is_same<
+ decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
+ true_type>::value>
+{
+};
+
+#else
+
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Alloc, class _Pointer, class ..._Args>
+struct __has_construct
+ : false_type
+{
+};
+
+#endif
+
+template <class _Alloc, class _Pointer>
+struct __has_destroy
+ : false_type
+{
+};
+
+template <class _Alloc>
+struct __has_max_size
+ : true_type
+{
+};
+
+template <class _Alloc>
+struct __has_select_on_container_copy_construction
+ : false_type
+{
+};
+
+#endif
+
+template <class _Alloc>
+struct allocator_traits
+{
+ typedef _Alloc allocator_type;
+ typedef typename allocator_type::value_type value_type;
+
+ typedef typename __pointer_type<value_type, allocator_type>::type pointer;
+ typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
+ typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
+ typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
+
+ typedef typename __pointer_traits_difference_type<allocator_type>::type difference_type;
+ typedef typename __size_type<allocator_type>::type size_type;
+
+ typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
+ propagate_on_container_copy_assignment;
+ typedef typename __propagate_on_container_move_assignment<allocator_type>::type
+ propagate_on_container_move_assignment;
+ typedef typename __propagate_on_container_swap<allocator_type>::type
+ propagate_on_container_swap;
+
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+ template <class _Tp> using rebind_alloc =
+ __allocator_traits_rebind<allocator_type, _Tp>::type;
+ template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
+#else
+ template <class _Tp> struct rebind_alloc
+ {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
+ template <class _Tp> struct rebind_traits
+ {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
+#endif
+
+ static pointer allocate(allocator_type& __a, size_type __n)
+ {return __a.allocate(__n);}
+ static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
+ {return allocate(__a, __n, __hint,
+ __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
+
+ static void deallocate(allocator_type& __a, pointer __p, size_type __n)
+ {__a.deallocate(__p, __n);}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+ template <class _Tp, class... _Args>
+ static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
+ {__construct(__has_construct<allocator_type, pointer, _Args...>(),
+ __a, __p, _STD::forward<_Args>(__args)...);}
+#else
+ template <class _Tp>
+ static void construct(allocator_type& __a, _Tp* __p)
+ {
+ ::new ((void*)__p) _Tp();
+ }
+ template <class _Tp, class _A0>
+ static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
+ {
+ ::new ((void*)__p) _Tp(__a0);
+ }
+ template <class _Tp, class _A0, class _A1>
+ static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
+ const _A1& __a1)
+ {
+ ::new ((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _Tp, class _A0, class _A1, class _A2>
+ static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
+ const _A1& __a1, const _A2& __a2)
+ {
+ ::new ((void*)__p) _Tp(__a0, __a1, __a2);
+ }
+#endif
+
+ template <class _Tp>
+ static void destroy(allocator_type& __a, _Tp* __p)
+ {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
+
+ static size_type max_size(const allocator_type& __a)
+ {return __max_size(__has_max_size<const allocator_type>(), __a);}
+
+ static allocator_type
+ select_on_container_copy_construction(const allocator_type& __a)
+ {return select_on_container_copy_construction(
+ __has_select_on_container_copy_construction<const allocator_type>(),
+ __a);}
+
+private:
+
+ static pointer allocate(allocator_type& __a, size_type __n,
+ const_void_pointer __hint, true_type)
+ {return __a.allocate(__n, __hint);}
+ static pointer allocate(allocator_type& __a, size_type __n,
+ const_void_pointer __hint, false_type)
+ {return __a.allocate(__n);}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+ template <class _Tp, class... _Args>
+ static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
+ {__a.construct(__p, _STD::forward<_Args>(__args)...);}
+ template <class _Tp, class... _Args>
+ static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
+ {
+ ::new ((void*)__p) _Tp(_STD::forward<_Args>(__args)...);
+ }
+#endif
+
+ template <class _Tp>
+ static void __destroy(true_type, allocator_type& __a, _Tp* __p)
+ {__a.destroy(__p);}
+ template <class _Tp>
+ static void __destroy(false_type, allocator_type&, _Tp* __p)
+ {
+ __p->~_Tp();
+ }
+
+ static size_type __max_size(true_type, const allocator_type& __a)
+ {return __a.max_size();}
+ static size_type __max_size(false_type, const allocator_type&)
+ {return numeric_limits<size_type>::max();}
+
+ static allocator_type
+ select_on_container_copy_construction(true_type, const allocator_type& __a)
+ {return __a.select_on_container_copy_construction();}
+ static allocator_type
+ select_on_container_copy_construction(false_type, const allocator_type& __a)
+ {return __a;}
+};
+
+// uses_allocator
+
+template <class _Tp>
+struct __has_allocator_type
+{
+private:
+ struct __two {char _; char __;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::allocator_type* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
+struct __uses_allocator
+ : public integral_constant<bool,
+ is_convertible<_Alloc, typename _Tp::allocator_type>::value>
+{
+};
+
+template <class _Tp, class _Alloc>
+struct __uses_allocator<_Tp, _Alloc, false>
+ : public false_type
+{
+};
+
+template <class _Tp, class _Alloc>
+struct uses_allocator
+ : public __uses_allocator<_Tp, _Alloc>
+{
+};
+
+#ifdef _LIBCPP_MOVE
+
+// uses-allocator construction
+
+template <class _Tp, class _Alloc, class ..._Args>
+struct __uses_alloc_ctor_imp
+{
+ static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
+ static const bool __ic =
+ is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
+ static const int value = __ua ? 2 - __ic : 0;
+};
+
+template <class _Tp, class _Alloc, class ..._Args>
+struct __uses_alloc_ctor
+ : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
+ {};
+
+// scoped_allocator_adaptor
+
+template <class ..._Allocs>
+class scoped_allocator_adaptor;
+
+template <class ..._Allocs> struct __get_poc_copy_assignment;
+
+template <class _A0>
+struct __get_poc_copy_assignment<_A0>
+{
+ static const bool value = allocator_traits<_A0>::
+ propagate_on_container_copy_assignment::value;
+};
+
+template <class _A0, class ..._Allocs>
+struct __get_poc_copy_assignment<_A0, _Allocs...>
+{
+ static const bool value =
+ allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
+ __get_poc_copy_assignment<_Allocs...>::value;
+};
+
+template <class ..._Allocs> struct __get_poc_move_assignment;
+
+template <class _A0>
+struct __get_poc_move_assignment<_A0>
+{
+ static const bool value = allocator_traits<_A0>::
+ propagate_on_container_move_assignment::value;
+};
+
+template <class _A0, class ..._Allocs>
+struct __get_poc_move_assignment<_A0, _Allocs...>
+{
+ static const bool value =
+ allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
+ __get_poc_move_assignment<_Allocs...>::value;
+};
+
+template <class ..._Allocs> struct __get_poc_swap;
+
+template <class _A0>
+struct __get_poc_swap<_A0>
+{
+ static const bool value = allocator_traits<_A0>::
+ propagate_on_container_swap::value;
+};
+
+template <class _A0, class ..._Allocs>
+struct __get_poc_swap<_A0, _Allocs...>
+{
+ static const bool value =
+ allocator_traits<_A0>::propagate_on_container_swap::value ||
+ __get_poc_swap<_Allocs...>::value;
+};
+
+template <class ..._Allocs>
+class __scoped_allocator_storage;
+
+template <class _OuterAlloc, class... _InnerAllocs>
+class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
+ : public _OuterAlloc
+{
+ typedef _OuterAlloc outer_allocator_type;
+protected:
+ typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
+
+private:
+ inner_allocator_type __inner_;
+
+protected:
+
+ __scoped_allocator_storage() {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ __scoped_allocator_storage(_OuterA2&& __outerAlloc,
+ const _InnerAllocs& ...__innerAllocs)
+ : outer_allocator_type(_STD::forward<_OuterA2>(__outerAlloc)),
+ __inner_(__innerAllocs...) {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, const _OuterA2&>::value
+ >::type>
+ __scoped_allocator_storage(
+ const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other)
+ : outer_allocator_type(__other.outer_allocator()),
+ __inner_(__other.inner_allocator()) {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ __scoped_allocator_storage(
+ __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other)
+ : outer_allocator_type(_STD::move(__other.outer_allocator())),
+ __inner_(_STD::move(__other.inner_allocator())) {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ __scoped_allocator_storage(_OuterA2&& __o,
+ const inner_allocator_type& __i)
+ : outer_allocator_type(_STD::forward<_OuterA2>(__o)),
+ __inner_(__i)
+ {
+ }
+
+ inner_allocator_type& inner_allocator() {return __inner_;}
+ const inner_allocator_type& inner_allocator() const {return __inner_;}
+
+ outer_allocator_type& outer_allocator()
+ {return static_cast<outer_allocator_type&>(*this);}
+ const outer_allocator_type& outer_allocator() const
+ {return static_cast<const outer_allocator_type&>(*this);}
+
+ scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
+ select_on_container_copy_construction() const
+ {
+ return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
+ (
+ allocator_traits<outer_allocator_type>::
+ select_on_container_copy_construction(outer_allocator()),
+ allocator_traits<inner_allocator_type>::
+ select_on_container_copy_construction(inner_allocator())
+ );
+ }
+
+ template <class...> friend class __scoped_allocator_storage;
+};
+
+template <class _OuterAlloc>
+class __scoped_allocator_storage<_OuterAlloc>
+ : public _OuterAlloc
+{
+ typedef _OuterAlloc outer_allocator_type;
+protected:
+ typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
+
+ __scoped_allocator_storage() {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ __scoped_allocator_storage(_OuterA2&& __outerAlloc)
+ : outer_allocator_type(_STD::forward<_OuterA2>(__outerAlloc)) {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, const _OuterA2&>::value
+ >::type>
+ __scoped_allocator_storage(
+ const __scoped_allocator_storage<_OuterA2>& __other)
+ : outer_allocator_type(__other.outer_allocator()) {}
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ __scoped_allocator_storage(
+ __scoped_allocator_storage<_OuterA2>&& __other)
+ : outer_allocator_type(_STD::move(__other.outer_allocator())) {}
+
+ inner_allocator_type& inner_allocator()
+ {return static_cast<inner_allocator_type&>(*this);}
+ const inner_allocator_type& inner_allocator() const
+ {return static_cast<const inner_allocator_type&>(*this);}
+
+ outer_allocator_type& outer_allocator()
+ {return static_cast<outer_allocator_type&>(*this);}
+ const outer_allocator_type& outer_allocator() const
+ {return static_cast<const outer_allocator_type&>(*this);}
+
+ scoped_allocator_adaptor<outer_allocator_type>
+ select_on_container_copy_construction() const
+ {return scoped_allocator_adaptor<outer_allocator_type>(
+ allocator_traits<outer_allocator_type>::
+ select_on_container_copy_construction(outer_allocator())
+ );}
+
+ __scoped_allocator_storage(const outer_allocator_type& __o,
+ const inner_allocator_type& __i);
+
+ template <class...> friend class __scoped_allocator_storage;
+};
+
+// __outermost
+
+template <class _Alloc>
+decltype(declval<_Alloc>().outer_allocator(), true_type())
+__has_outer_allocator_test(_Alloc&& __a);
+
+template <class _Alloc>
+false_type
+__has_outer_allocator_test(const volatile _Alloc& __a);
+
+template <class _Alloc>
+struct __has_outer_allocator
+ : public common_type
+ <
+ decltype(__has_outer_allocator_test(declval<_Alloc&>()))
+ >::type
+{
+};
+
+template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
+struct __outermost
+{
+ typedef _Alloc type;
+ type& operator()(type& __a) const {return __a;}
+};
+
+template <class _Alloc>
+struct __outermost<_Alloc, true>
+{
+ typedef typename remove_reference
+ <
+ decltype(_STD::declval<_Alloc>().outer_allocator())
+ >::type _OuterAlloc;
+ typedef typename __outermost<_OuterAlloc>::type type;
+ type& operator()(_Alloc& __a) const
+ {return __outermost<_OuterAlloc>()(__a.outer_allocator());}
+};
+
+template <class _OuterAlloc, class... _InnerAllocs>
+class scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
+ : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
+{
+ typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
+ typedef allocator_traits<_OuterAlloc> _OuterTraits;
+public:
+ typedef _OuterAlloc outer_allocator_type;
+ typedef typename base::inner_allocator_type inner_allocator_type;
+ typedef typename _OuterTraits::size_type size_type;
+ typedef typename _OuterTraits::difference_type difference_type;
+ typedef typename _OuterTraits::pointer pointer;
+ typedef typename _OuterTraits::const_pointer const_pointer;
+ typedef typename _OuterTraits::void_pointer void_pointer;
+ typedef typename _OuterTraits::const_void_pointer const_void_pointer;
+
+ typedef integral_constant
+ <
+ bool,
+ __get_poc_copy_assignment<outer_allocator_type,
+ _InnerAllocs...>::value
+ > propagate_on_container_copy_assignment;
+ typedef integral_constant
+ <
+ bool,
+ __get_poc_move_assignment<outer_allocator_type,
+ _InnerAllocs...>::value
+ > propagate_on_container_move_assignment;
+ typedef integral_constant
+ <
+ bool,
+ __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
+ > propagate_on_container_swap;
+
+ template <class _Tp>
+ struct rebind
+ {
+ typedef scoped_allocator_adaptor
+ <
+ typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
+ > other;
+ };
+
+ scoped_allocator_adaptor() {}
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
+ const _InnerAllocs& ...__innerAllocs)
+ : base(_STD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
+ // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, const _OuterA2&>::value
+ >::type>
+ scoped_allocator_adaptor(
+ const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other)
+ : base(__other) {}
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ scoped_allocator_adaptor(
+ scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other)
+ : base(_STD::move(__other)) {}
+
+ // ~scoped_allocator_adaptor() = default;
+
+ inner_allocator_type& inner_allocator()
+ {return base::inner_allocator();}
+ const inner_allocator_type& inner_allocator() const
+ {return base::inner_allocator();}
+
+ outer_allocator_type& outer_allocator()
+ {return base::outer_allocator();}
+ const outer_allocator_type& outer_allocator() const
+ {return base::outer_allocator();}
+
+ pointer allocate(size_type __n)
+ {return allocator_traits<outer_allocator_type>::
+ allocate(outer_allocator(), __n);}
+ pointer allocate(size_type __n, const_void_pointer __hint)
+ {return allocator_traits<outer_allocator_type>::
+ allocate(outer_allocator(), __n, __hint);}
+
+ void deallocate(pointer __p, size_type __n)
+ {allocator_traits<outer_allocator_type>::
+ deallocate(outer_allocator(), __p, __n);}
+
+ size_type max_size() const
+ {allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
+
+ template <class _Tp, class... _Args>
+ void construct(_Tp* __p, _Args&& ...__args)
+ {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(),
+ __p, _STD::forward<_Args>(__args)...);}
+ template <class _Tp>
+ void destroy(_Tp* __p)
+ {
+ typedef __outermost<outer_allocator_type> _OM;
+ allocator_traits<typename _OM::type>::
+ destroy(_OM()(outer_allocator()), __p);
+ }
+
+ scoped_allocator_adaptor select_on_container_copy_construction() const
+ {return base::select_on_container_copy_construction();}
+
+private:
+
+ template <class _OuterA2,
+ class = typename enable_if<
+ is_constructible<outer_allocator_type, _OuterA2>::value
+ >::type>
+ scoped_allocator_adaptor(_OuterA2&& __o,
+ const inner_allocator_type& __i)
+ : base(_STD::forward<_OuterA2>(__o), __i) {}
+
+ template <class _Tp, class... _Args>
+ void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
+ {
+ typedef __outermost<outer_allocator_type> _OM;
+ allocator_traits<typename _OM::type>::construct
+ (
+ _OM()(outer_allocator()),
+ __p,
+ _STD::forward<_Args>(__args)...
+ );
+ }
+
+ template <class _Tp, class... _Args>
+ void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
+ {
+ typedef __outermost<outer_allocator_type> _OM;
+ allocator_traits<typename _OM::type>::construct
+ (
+ _OM()(outer_allocator()),
+ __p,
+ allocator_arg,
+ inner_allocator(),
+ _STD::forward<_Args>(__args)...
+ );
+ }
+
+ template <class _Tp, class... _Args>
+ void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
+ {
+ typedef __outermost<outer_allocator_type> _OM;
+ allocator_traits<typename _OM::type>::construct
+ (
+ _OM()(outer_allocator()),
+ __p,
+ _STD::forward<_Args>(__args)...,
+ inner_allocator()
+ );
+ }
+
+ template <class...> friend class __scoped_allocator_storage;
+};
+
+template <class _OuterA1, class _OuterA2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
+ const scoped_allocator_adaptor<_OuterA2>& __b)
+{
+ return __a.outer_allocator() == __b.outer_allocator();
+}
+
+template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
+ const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b)
+{
+ return __a.outer_allocator() == __b.outer_allocator() &&
+ __a.inner_allocator() == __b.inner_allocator();
+}
+
+template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
+ const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b)
+{
+ return !(__a == __b);
+}
+
+#endif
+
+// allocator
+
+template <class _Tp>
+class allocator
+{
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp value_type;
+
+ template <class _Up> struct rebind {typedef allocator<_Up> other;};
+
+ _LIBCPP_INLINE_VISIBILITY allocator() throw() {}
+ template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) throw() {}
+ _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const {return addressof(__x);}
+ _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const {return addressof(__x);}
+ _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
+ {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
+ _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) {::operator delete((void*)__p);}
+ _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
+#ifdef _LIBCPP_MOVE
+ template <class _Up, class... _Args>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(_Up* __p, _Args&&... __args)
+ {
+ ::new((void*)__p) _Up(_STD::forward<_Args>(__args)...);
+ }
+#else
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p)
+ {
+ ::new((void*)__p) _Tp();
+ }
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ !is_convertible<_A0, __rv<_A0> >::value,
+ void
+ >::type
+ construct(pointer __p, _A0& __a0)
+ {
+ ::new((void*)__p) _Tp(__a0);
+ }
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ !is_convertible<_A0, __rv<_A0> >::value,
+ void
+ >::type
+ construct(pointer __p, const _A0& __a0)
+ {
+ ::new((void*)__p) _Tp(__a0);
+ }
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ is_convertible<_A0, __rv<_A0> >::value,
+ void
+ >::type
+ construct(pointer __p, _A0 __a0)
+ {
+ ::new((void*)__p) _Tp(_STD::move(__a0));
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, _A0& __a0, _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, const _A0& __a0, _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, _A0& __a0, const _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, const _A0& __a0, const _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+#endif
+ _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
+};
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator==(const allocator<_Tp>&, const allocator<_Up>&) throw() {return true;}
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) throw() {return false;}
+
+template <class _OutputIterator, class _Tp>
+class raw_storage_iterator
+ : public iterator<output_iterator_tag,
+ _Tp, // purposefully not C++03
+ ptrdiff_t, // purposefully not C++03
+ _Tp*, // purposefully not C++03
+ raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
+{
+private:
+ _OutputIterator __x_;
+public:
+ _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
+ _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
+ _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
+ {::new(&*__x_) _Tp(__element); return *this;}
+ _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
+ _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
+ {raw_storage_iterator __t(*this); ++__x_; return __t;}
+};
+
+template <class _Tp>
+pair<_Tp*, ptrdiff_t>
+get_temporary_buffer(ptrdiff_t __n)
+{
+ pair<_Tp*, ptrdiff_t> __r(0, 0);
+ const ptrdiff_t __m = (~ptrdiff_t(0) ^
+ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
+ / sizeof(_Tp);
+ if (__n > __m)
+ __n = __m;
+ while (__n > 0)
+ {
+ __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
+ if (__r.first)
+ {
+ __r.second = __n;
+ break;
+ }
+ __n /= 2;
+ }
+ return __r;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void return_temporary_buffer(_Tp* __p) {::operator delete(__p);}
+
+template <class _Tp>
+struct auto_ptr_ref
+{
+ _Tp* __ptr_;
+};
+
+template<class _Tp>
+class auto_ptr
+{
+private:
+ _Tp* __ptr_;
+public:
+ typedef _Tp element_type;
+
+ _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
+ _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
+ template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
+ : __ptr_(__p.release()) {}
+ _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
+ {reset(__p.release()); return *this;}
+ template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
+ {reset(__p.release()); return *this;}
+ _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
+ {reset(__p.__ptr_); return *this;}
+ _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
+
+ _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
+ {return *__ptr_;}
+ _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
+ _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
+ _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
+ {
+ _Tp* __t = __ptr_;
+ __ptr_ = 0;
+ return __t;
+ }
+ _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
+ {
+ if (__ptr_ != __p)
+ delete __ptr_;
+ __ptr_ = __p;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
+ template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
+ {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
+ template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
+ {return auto_ptr<_Up>(release());}
+};
+
+template <>
+class auto_ptr<void>
+{
+public:
+ typedef void element_type;
+};
+
+
+template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
+ typename remove_cv<_T2>::type>::value,
+ bool = is_empty<_T1>::value,
+ bool = is_empty<_T2>::value>
+struct __libcpp_compressed_pair_switch;
+
+template <class _T1, class _T2, bool IsSame>
+struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
+
+template <class _T1, class _T2, bool IsSame>
+struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
+
+template <class _T1, class _T2, bool IsSame>
+struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
+
+template <class _T1, class _T2>
+struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
+
+template <class _T1, class _T2>
+struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
+
+template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
+class __libcpp_compressed_pair_imp;
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 0>
+{
+private:
+ _T1 __first_;
+ _T2 __second_;
+public:
+ typedef _T1 _T1_param;
+ typedef _T2 _T2_param;
+
+ typedef typename remove_reference<_T1>::type& _T1_reference;
+ typedef typename remove_reference<_T2>::type& _T2_reference;
+
+ typedef const typename remove_reference<_T1>::type& _T1_const_reference;
+ typedef const typename remove_reference<_T2>::type& _T2_const_reference;
+
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
+ : __first_(_STD::forward<_T1_param>(__t1)) {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0)
+ : __second_(_STD::forward<_T2_param>(__t2)) {}
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+ : __first_(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+ : __first_(_STD::forward<_T1>(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {}
+#endif
+
+ _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return __first_;}
+ _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return __first_;}
+
+ _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return __second_;}
+ _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return __second_;}
+
+ _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+ {
+ using _STD::swap;
+ swap(__first_, __x.__first_);
+ swap(__second_, __x.__second_);
+ }
+};
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 1>
+ : private _T1
+{
+private:
+ _T2 __second_;
+public:
+ typedef _T1 _T1_param;
+ typedef _T2 _T2_param;
+
+ typedef _T1& _T1_reference;
+ typedef typename remove_reference<_T2>::type& _T2_reference;
+
+ typedef const _T1& _T1_const_reference;
+ typedef const typename remove_reference<_T2>::type& _T2_const_reference;
+
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
+ : _T1(_STD::forward<_T1_param>(__t1)) {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0)
+ : __second_(_STD::forward<_T2_param>(__t2)) {}
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+ : _T1(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+ : _T1(_STD::move(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {}
+#endif
+
+ _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return *this;}
+ _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return *this;}
+
+ _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return __second_;}
+ _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return __second_;}
+
+ _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+ {
+ using _STD::swap;
+ swap(__second_, __x.__second_);
+ }
+};
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 2>
+ : private _T2
+{
+private:
+ _T1 __first_;
+public:
+ typedef _T1 _T1_param;
+ typedef _T2 _T2_param;
+
+ typedef typename remove_reference<_T1>::type& _T1_reference;
+ typedef _T2& _T2_reference;
+
+ typedef const typename remove_reference<_T1>::type& _T1_const_reference;
+ typedef const _T2& _T2_const_reference;
+
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
+ : __first_(_STD::forward<_T1_param>(__t1)) {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
+ : _T2(_STD::forward<_T2_param>(__t2)) {}
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+ : _T2(_STD::forward<_T2_param>(__t2)), __first_(_STD::forward<_T1_param>(__t1)) {}
+
+#ifdef _LIBCPP_MOVE
+ __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+ : _T2(_STD::forward<_T2>(__p.second())), __first_(_STD::move(__p.first())) {}
+#endif
+
+ _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return __first_;}
+ _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return __first_;}
+
+ _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return *this;}
+ _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return *this;}
+
+ _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+ {
+ using _STD::swap;
+ swap(__first_, __x.__first_);
+ }
+};
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 3>
+ : private _T1,
+ private _T2
+{
+public:
+ typedef _T1 _T1_param;
+ typedef _T2 _T2_param;
+
+ typedef _T1& _T1_reference;
+ typedef _T2& _T2_reference;
+
+ typedef const _T1& _T1_const_reference;
+ typedef const _T2& _T2_const_reference;
+
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
+ : _T1(_STD::forward<_T1_param>(__t1)) {}
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
+ : _T2(_STD::forward<_T2_param>(__t2)) {}
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+ : _T1(_STD::forward<_T1_param>(__t1)), _T2(_STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+ _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+ : _T1(_STD::move(__p.first())), _T2(_STD::move(__p.second())) {}
+#endif
+
+ _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return *this;}
+ _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return *this;}
+
+ _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return *this;}
+ _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return *this;}
+
+ _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+ {
+ }
+};
+
+template <class _T1, class _T2>
+class __compressed_pair
+ : private __libcpp_compressed_pair_imp<_T1, _T2>
+{
+ typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
+public:
+ typedef typename base::_T1_param _T1_param;
+ typedef typename base::_T2_param _T2_param;
+
+ typedef typename base::_T1_reference _T1_reference;
+ typedef typename base::_T2_reference _T2_reference;
+
+ typedef typename base::_T1_const_reference _T1_const_reference;
+ typedef typename base::_T2_const_reference _T2_const_reference;
+
+ _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
+ _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0)
+ : base(_STD::forward<_T1_param>(__t1)) {}
+ _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2, int* = 0)
+ : base(_STD::forward<_T2_param>(__t2)) {}
+ _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
+ : base(_STD::forward<_T1_param>(__t1), _STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+ __compressed_pair(__compressed_pair&& __p)
+ : base(_STD::move(__p)) {}
+#endif
+
+ _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return base::first();}
+ _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return base::first();}
+
+ _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return base::second();}
+ _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return base::second();}
+
+ _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) {base::swap(__x);}
+};
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
+ {__x.swap(__y);}
+
+template <class _Tp>
+struct default_delete
+{
+ _LIBCPP_INLINE_VISIBILITY default_delete() {}
+ template <class _Up>
+ _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
+ typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) {}
+ _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const
+ {
+ static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
+ delete __ptr;
+ }
+};
+
+template <class _Tp>
+struct default_delete<_Tp[]>
+{
+ _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const
+ {
+ static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
+ delete [] __ptr;
+ }
+private:
+ template <class _Up> void operator() (_Up*) const;
+};
+
+template <class _Tp, class _Dp = default_delete<_Tp> >
+class unique_ptr
+{
+public:
+ typedef _Tp element_type;
+ typedef _Dp deleter_type;
+ typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
+private:
+ __compressed_pair<pointer, deleter_type> __ptr_;
+
+#ifdef _LIBCPP_MOVE
+ unique_ptr(const unique_ptr&);
+ unique_ptr& operator=(const unique_ptr&);
+ template <class _Up, class _Ep>
+ unique_ptr(const unique_ptr<_Up, _Ep>&);
+ template <class _Up, class _Ep>
+ unique_ptr& operator=(const unique_ptr<_Up, _Ep>&);
+#else
+ unique_ptr(unique_ptr&);
+ template <class _Up, class _Ep>
+ unique_ptr(unique_ptr<_Up, _Ep>&);
+ unique_ptr& operator=(unique_ptr&);
+ template <class _Up, class _Ep>
+ unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
+#endif
+
+ struct __nat {int __for_bool_;};
+
+ typedef typename remove_reference<deleter_type>::type& _Dp_reference;
+ typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
+public:
+ _LIBCPP_INLINE_VISIBILITY unique_ptr()
+ : __ptr_(pointer())
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t)
+ : __ptr_(pointer())
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+ _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
+ : __ptr_(_STD::move(__p))
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+
+ template <class _Up>
+ _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(auto_ptr<_Up>& __p,
+ typename enable_if<
+ is_convertible<_Up*, _Tp*>::value &&
+ is_same<_Dp, default_delete<_Tp> >::value,
+ __nat
+ >::type = __nat())
+ : __ptr_(__p.release())
+ {
+ }
+
+#ifdef _LIBCPP_MOVE
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
+ is_reference<deleter_type>::value,
+ deleter_type,
+ typename add_lvalue_reference<const deleter_type>::type>::type __d)
+ : __ptr_(__p, __d) {}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
+ : __ptr_(__p, _STD::move(__d))
+ {
+ static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
+ }
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u)
+ : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {}
+ template <class _Up, class _Ep>
+ _LIBCPP_INLINE_VISIBILITY
+ unique_ptr(unique_ptr<_Up, _Ep>&& __u,
+ typename enable_if
+ <
+ !is_array<_Up>::value &&
+ is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
+ is_convertible<_Ep, deleter_type>::value &&
+ (
+ !is_reference<deleter_type>::value ||
+ is_same<deleter_type, _Ep>::value
+ ),
+ __nat
+ >::type = __nat())
+ : __ptr_(__u.release(), _STD::forward<_Ep>(__u.get_deleter())) {}
+
+ template <class _Up>
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
+ typename enable_if<
+ is_convertible<_Up*, _Tp*>::value &&
+ is_same<_Dp, default_delete<_Tp> >::value,
+ __nat
+ >::type = __nat())
+ : __ptr_(__p.release())
+ {
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u)
+ {
+ reset(__u.release());
+ __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter());
+ return *this;
+ }
+
+ template <class _Up, class _Ep>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ !is_array<_Up>::value,
+ unique_ptr&
+ >::type
+ operator=(unique_ptr<_Up, _Ep>&& __u)
+ {
+ reset(__u.release());
+ __ptr_.second() = _STD::forward<_Ep>(__u.get_deleter());
+ return *this;
+ }
+#else
+
+ _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
+ {
+ return __rv<unique_ptr>(*this);
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
+ : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {}
+
+ template <class _Up, class _Ep>
+ _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
+ {
+ reset(__u.release());
+ __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter());
+ return *this;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
+ : __ptr_(_STD::move(__p), _STD::move(__d)) {}
+
+ template <class _Up>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if<
+ is_convertible<_Up*, _Tp*>::value &&
+ is_same<_Dp, default_delete<_Tp> >::value,
+ unique_ptr&
+ >::type
+ operator=(auto_ptr<_Up> __p)
+ {reset(__p.release()); return *this;}
+
+#endif
+ _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t)
+ {
+ reset();
+ return *this;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
+ {return *__ptr_.first();}
+ _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_.first();}
+ _LIBCPP_INLINE_VISIBILITY pointer get() const {return __ptr_.first();}
+ _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() {return __ptr_.second();}
+ _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const {return __ptr_.second();}
+ _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const {return __ptr_.first() ? &__nat::__for_bool_ : 0;}
+
+ _LIBCPP_INLINE_VISIBILITY pointer release()
+ {
+ pointer __t = __ptr_.first();
+ __ptr_.first() = pointer();
+ return __t;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
+ {
+ pointer __tmp = __ptr_.first();
+ __ptr_.first() = __p;
+ if (__tmp)
+ __ptr_.second()(__tmp);
+ }
+
+ _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
+};
+
+template <class _Tp, class _Dp>
+class unique_ptr<_Tp[], _Dp>
+{
+public:
+ typedef _Tp element_type;
+ typedef _Dp deleter_type;
+ typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
+private:
+ __compressed_pair<pointer, deleter_type> __ptr_;
+
+#ifdef _LIBCPP_MOVE
+ unique_ptr(const unique_ptr&);
+ unique_ptr& operator=(const unique_ptr&);
+#else
+ unique_ptr(unique_ptr&);
+ template <class _Up>
+ unique_ptr(unique_ptr<_Up>&);
+ unique_ptr& operator=(unique_ptr&);
+ template <class _Up>
+ unique_ptr& operator=(unique_ptr<_Up>&);
+#endif
+
+ struct __nat {int __for_bool_;};
+
+ typedef typename remove_reference<deleter_type>::type& _Dp_reference;
+ typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
+public:
+ _LIBCPP_INLINE_VISIBILITY unique_ptr()
+ : __ptr_(pointer())
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t)
+ : __ptr_(pointer())
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+#ifdef _LIBCPP_MOVE
+ template <class _P,
+ class = typename enable_if<is_same<_P, pointer>::value>::type
+ >
+ _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_P __p)
+ : __ptr_(__p)
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+
+ template <class _P,
+ class = typename enable_if<is_same<_P, pointer>::value>::type
+ >
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename conditional<
+ is_reference<deleter_type>::value,
+ deleter_type,
+ typename add_lvalue_reference<const deleter_type>::type>::type __d)
+ : __ptr_(__p, __d) {}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
+ is_reference<deleter_type>::value,
+ deleter_type,
+ typename add_lvalue_reference<const deleter_type>::type>::type __d)
+ : __ptr_(pointer(), __d) {}
+
+ template <class _P,
+ class = typename enable_if<is_same<_P, pointer>::value ||
+ is_same<_P, nullptr_t>::value>::type
+ >
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename remove_reference<deleter_type>::type&& __d)
+ : __ptr_(__p, _STD::move(__d))
+ {
+ static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
+ : __ptr_(pointer(), _STD::move(__d))
+ {
+ static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u)
+ : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u)
+ {
+ reset(__u.release());
+ __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter());
+ return *this;
+ }
+#else
+
+ _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
+ : __ptr_(__p)
+ {
+ static_assert(!is_pointer<deleter_type>::value,
+ "unique_ptr constructed with null function pointer deleter");
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
+ : __ptr_(__p, _STD::forward<deleter_type>(__d)) {}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
+ : __ptr_(pointer(), _STD::forward<deleter_type>(__d)) {}
+
+ _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
+ {
+ return __rv<unique_ptr>(*this);
+ }
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
+ : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
+ {
+ reset(__u->release());
+ __ptr_.second() = _STD::forward<deleter_type>(__u->get_deleter());
+ return *this;
+ }
+
+#endif
+ _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
+
+ _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t)
+ {
+ reset();
+ return *this;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
+ {return __ptr_.first()[__i];}
+ _LIBCPP_INLINE_VISIBILITY pointer get() const {return __ptr_.first();}
+ _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() {return __ptr_.second();}
+ _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const {return __ptr_.second();}
+ _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const {return __ptr_.first() ? &__nat::__for_bool_ : 0;}
+
+ _LIBCPP_INLINE_VISIBILITY pointer release()
+ {
+ pointer __t = __ptr_.first();
+ __ptr_.first() = pointer();
+ return __t;
+ }
+
+#ifdef _LIBCPP_MOVE
+ template <class _P,
+ class = typename enable_if<is_same<_P, pointer>::value>::type
+ >
+ _LIBCPP_INLINE_VISIBILITY void reset(_P __p)
+ {
+ pointer __tmp = __ptr_.first();
+ __ptr_.first() = __p;
+ if (__tmp)
+ __ptr_.second()(__tmp);
+ }
+ _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t)
+ {
+ pointer __tmp = __ptr_.first();
+ __ptr_.first() = nullptr;
+ if (__tmp)
+ __ptr_.second()(__tmp);
+ }
+ _LIBCPP_INLINE_VISIBILITY void reset()
+ {
+ pointer __tmp = __ptr_.first();
+ __ptr_.first() = nullptr;
+ if (__tmp)
+ __ptr_.second()(__tmp);
+ }
+#else
+ _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
+ {
+ pointer __tmp = __ptr_.first();
+ __ptr_.first() = __p;
+ if (__tmp)
+ __ptr_.second()(__tmp);
+ }
+#endif
+
+ _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
+private:
+
+#ifndef _LIBCPP_MOVE
+ template <class _Up>
+ explicit unique_ptr(_Up);
+ template <class _Up>
+ unique_ptr(_Up __u,
+ typename conditional<
+ is_reference<deleter_type>::value,
+ deleter_type,
+ typename add_lvalue_reference<const deleter_type>::type>::type,
+ typename enable_if
+ <
+ is_convertible<_Up, pointer>::value,
+ __nat
+ >::type = __nat());
+#endif
+};
+
+template <class _Tp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) {__x.swap(__y);}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() < __y.get();}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
+
+struct __destruct_n
+{
+private:
+ size_t size;
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type)
+ {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type)
+ {}
+
+ _LIBCPP_INLINE_VISIBILITY void __incr(false_type)
+ {++size;}
+ _LIBCPP_INLINE_VISIBILITY void __incr(true_type)
+ {}
+
+ _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type)
+ {size = __s;}
+ _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type)
+ {}
+public:
+ _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) : size(__s) {}
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*)
+ {__incr(integral_constant<bool, has_trivial_destructor<_Tp>::value>());}
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*)
+ {__set(__s, integral_constant<bool, has_trivial_destructor<_Tp>::value>());}
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p)
+ {__process(__p, integral_constant<bool, has_trivial_destructor<_Tp>::value>());}
+};
+
+template <class _Alloc>
+class __allocator_destructor
+{
+ typedef allocator_traits<_Alloc> __alloc_traits;
+public:
+ typedef typename __alloc_traits::pointer pointer;
+ typedef typename __alloc_traits::size_type size_type;
+private:
+ _Alloc& __alloc_;
+ size_type __s_;
+public:
+ _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
+ : __alloc_(__a), __s_(__s) {}
+ void operator()(pointer __p) {__alloc_traits::deallocate(__alloc_, __p, __s_);}
+};
+
+template <class _InputIterator, class _ForwardIterator>
+_ForwardIterator
+uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
+{
+ __destruct_n __d(0);
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ unique_ptr<value_type, __destruct_n&> __h(&*__r, __d);
+ for (; __f != __l; ++__f, ++__r, __d.__incr((value_type*)0))
+ ::new(&*__r) value_type(*__f);
+ __h.release();
+ return __r;
+}
+
+template <class _InputIterator, class _Size, class _ForwardIterator>
+_ForwardIterator
+uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
+{
+ __destruct_n __d(0);
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ unique_ptr<value_type, __destruct_n&> __h(&*__r, __d);
+ for (; __n > 0; ++__f, ++__r, __d.__incr((value_type*)0), --__n)
+ ::new(&*__r) value_type(*__f);
+ __h.release();
+ return __r;
+}
+
+template <class _ForwardIterator, class _Tp>
+void
+uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
+{
+ __destruct_n __d(0);
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ unique_ptr<value_type, __destruct_n&> __h(&*__f, __d);
+ for (; __f != __l; ++__f, __d.__incr((value_type*)0))
+ ::new(&*__f) value_type(__x);
+ __h.release();
+}
+
+template <class _ForwardIterator, class _Size, class _Tp>
+void
+uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
+{
+ __destruct_n __d(0);
+ typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+ unique_ptr<value_type, __destruct_n&> __h(&*__f, __d);
+ for (; __n > 0; ++__f, --__n, __d.__incr((value_type*)0))
+ ::new(&*__f) value_type(__x);
+ __h.release();
+}
+
+class bad_weak_ptr
+ : public std::exception
+{
+public:
+ virtual ~bad_weak_ptr() throw();
+ virtual const char* what() const throw();
+};
+
+template<class _Tp> class weak_ptr;
+
+class __shared_count
+{
+ __shared_count(const __shared_count&);
+ __shared_count& operator=(const __shared_count&);
+
+protected:
+ long __shared_owners_;
+ virtual ~__shared_count();
+private:
+ virtual void __on_zero_shared() = 0;
+
+public:
+ explicit __shared_count(long __refs = 0)
+ : __shared_owners_(__refs) {}
+
+ void __add_shared();
+ void __release_shared();
+ long use_count() const {return __shared_owners_ + 1;}
+};
+
+class __shared_weak_count
+ : private __shared_count
+{
+ long __shared_weak_owners_;
+
+public:
+ explicit __shared_weak_count(long __refs = 0)
+ : __shared_count(__refs),
+ __shared_weak_owners_(__refs) {}
+protected:
+ virtual ~__shared_weak_count();
+
+public:
+ void __add_shared();
+ void __add_weak();
+ void __release_shared();
+ void __release_weak();
+ long use_count() const {return __shared_count::use_count();}
+ __shared_weak_count* lock();
+
+ virtual const void* __get_deleter(const type_info&) const;
+private:
+ virtual void __on_zero_shared_weak() = 0;
+};
+
+template <class _Tp, class _Dp, class _Alloc>
+class __shared_ptr_pointer
+ : public __shared_weak_count
+{
+ __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
+public:
+ __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
+ : __data_(__compressed_pair<_Tp, _Dp>(__p, _STD::move(__d)), _STD::move(__a)) {}
+
+ virtual const void* __get_deleter(const type_info&) const;
+
+private:
+ virtual void __on_zero_shared();
+ virtual void __on_zero_shared_weak();
+};
+
+template <class _Tp, class _Dp, class _Alloc>
+const void*
+__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const
+{
+ return __t == typeid(_Dp) ? &__data_.first().second() : 0;
+}
+
+template <class _Tp, class _Dp, class _Alloc>
+void
+__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared()
+{
+ __data_.first().second()(__data_.first().first());
+ __data_.first().second().~_Dp();
+}
+
+template <class _Tp, class _Dp, class _Alloc>
+void
+__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak()
+{
+ typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
+ __data_.second().~_Alloc();
+ __a.deallocate(this, 1);
+}
+
+template <class _Tp, class _Alloc>
+class __shared_ptr_emplace
+ : public __shared_weak_count
+{
+ __compressed_pair<_Alloc, _Tp> __data_;
+public:
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ __shared_ptr_emplace(_Alloc __a)
+ : __data_(_STD::move(__a)) {}
+
+ template <class ..._Args>
+ __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
+ : __data_(_STD::move(__a), _Tp(_STD::forward<_Args>(__args)...)) {}
+
+#else // _LIBCPP_HAS_NO_VARIADICS
+
+ __shared_ptr_emplace(_Alloc __a)
+ : __data_(__a) {}
+
+ template <class _A0>
+ __shared_ptr_emplace(_Alloc __a, _A0& __a0)
+ : __data_(__a, _Tp(__a0)) {}
+
+ template <class _A0, class _A1>
+ __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
+ : __data_(__a, _Tp(__a0, __a1)) {}
+
+ template <class _A0, class _A1, class _A2>
+ __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
+ : __data_(__a, _Tp(__a0, __a1, __a2)) {}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
+private:
+ virtual void __on_zero_shared();
+ virtual void __on_zero_shared_weak();
+public:
+ _Tp* get() {return &__data_.second();}
+};
+
+template <class _Tp, class _Alloc>
+void
+__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared()
+{
+ __data_.second().~_Tp();
+}
+
+template <class _Tp, class _Alloc>
+void
+__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak()
+{
+ typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
+ __data_.first().~_Alloc();
+ __a.deallocate(this, 1);
+}
+
+template<class _Tp> class enable_shared_from_this;
+
+template<class _Tp>
+class shared_ptr
+{
+public:
+ typedef _Tp element_type;
+private:
+ element_type* __ptr_;
+ __shared_weak_count* __cntrl_;
+
+ struct __nat {int __for_bool_;};
+public:
+ shared_ptr();
+ shared_ptr(nullptr_t);
+ template<class _Yp> explicit shared_ptr(_Yp* __p);
+ template<class _Yp, class _Dp> shared_ptr(_Yp* __p, _Dp __d);
+ template<class _Yp, class _Dp, class _Alloc> shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
+ template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
+ template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
+ template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p);
+ shared_ptr(const shared_ptr& __r);
+ template<class _Yp>
+ shared_ptr(const shared_ptr<_Yp>& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat());
+#ifdef _LIBCPP_MOVE
+ shared_ptr(shared_ptr&& __r);
+ template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat());
+#endif
+ template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
+#ifdef _LIBCPP_MOVE
+ template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r);
+#else
+ template<class _Yp> shared_ptr(auto_ptr<_Yp>& __r);
+#endif
+#ifdef _LIBCPP_MOVE
+private:
+ template <class _Yp, class _Dp> shared_ptr(const unique_ptr<_Yp, _Dp>& __r);// = delete;
+public:
+ template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&,
+ typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+ template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&,
+ typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+#else
+ template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>,
+ typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+ template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>,
+ typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+#endif
+
+ ~shared_ptr();
+
+ shared_ptr& operator=(const shared_ptr& __r);
+ template<class _Yp> shared_ptr& operator=(const shared_ptr<_Yp>& __r);
+#ifdef _LIBCPP_MOVE
+ shared_ptr& operator=(shared_ptr&& __r);
+ template<class _Yp> shared_ptr& operator=(shared_ptr<_Yp>&& __r);
+ template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>&& __r);
+#else
+ template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>& __r);
+#endif
+#ifdef _LIBCPP_MOVE
+private:
+ template <class _Yp, class _Dp> shared_ptr& operator=(const unique_ptr<_Yp, _Dp>& __r);// = delete;
+public:
+ template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp>&& __r);
+#else
+ template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp> __r);
+#endif
+
+ void swap(shared_ptr& __r);
+ void reset();
+ template<class _Yp> void reset(_Yp* __p);
+ template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d);
+ template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a);
+
+ element_type* get() const {return __ptr_;}
+ typename add_lvalue_reference<element_type>::type operator*() const {return *__ptr_;}
+ element_type* operator->() const {return __ptr_;}
+ long use_count() const {return __cntrl_ ? __cntrl_->use_count() : 0;}
+ bool unique() const {return use_count() == 1;}
+ bool empty() const {return __cntrl_ == 0;}
+ /*explicit*/ operator bool() const {return get() != 0;}
+ template <class _U> bool owner_before(shared_ptr<_U> const& __p) const
+ {return __cntrl_ < __p.__cntrl_;}
+ template <class _U> bool owner_before(weak_ptr<_U> const& __p) const
+ {return __cntrl_ < __p.__cntrl_;}
+
+ template <class _Dp>
+ _Dp* __get_deleter() const
+ {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ template<class ..._Args>
+ static
+ shared_ptr<_Tp>
+ make_shared(_Args&& ...__args);
+
+ template<class _Alloc, class ..._Args>
+ static
+ shared_ptr<_Tp>
+ allocate_shared(const _Alloc& __a, _Args&& ...__args);
+
+#else // _LIBCPP_HAS_NO_VARIADICS
+
+ static shared_ptr<_Tp> make_shared();
+
+ template<class _A0>
+ static shared_ptr<_Tp> make_shared(_A0&);
+
+ template<class _A0, class _A1>
+ static shared_ptr<_Tp> make_shared(_A0&, _A1&);
+
+ template<class _A0, class _A1, class _A2>
+ static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
+
+ template<class _Alloc>
+ static shared_ptr<_Tp>
+ allocate_shared(const _Alloc& __a);
+
+ template<class _Alloc, class _A0>
+ static shared_ptr<_Tp>
+ allocate_shared(const _Alloc& __a, _A0& __a0);
+
+ template<class _Alloc, class _A0, class _A1>
+ static shared_ptr<_Tp>
+ allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
+
+ template<class _Alloc, class _A0, class _A1, class _A2>
+ static shared_ptr<_Tp>
+ allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
+private:
+
+ template <class _Yp>
+ void
+ __enable_weak_this(const enable_shared_from_this<_Yp>* __e)
+ {
+ if (__e)
+ __e->__weak_this_ = *this;
+ }
+
+ void __enable_weak_this(const void*) {}
+
+ template <class _Up> friend class shared_ptr;
+ template <class _Up> friend class weak_ptr;
+};
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr()
+ : __ptr_(0),
+ __cntrl_(0)
+{
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(nullptr_t)
+ : __ptr_(0),
+ __cntrl_(0)
+{
+}
+
+template<class _Tp>
+template<class _Yp>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p)
+ : __ptr_(__p)
+{
+ unique_ptr<_Yp> __hold(__p);
+ typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
+ __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
+ __hold.release();
+ __enable_weak_this(__p);
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
+ : __ptr_(__p)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
+ {
+#endif
+ typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
+ __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
+ __enable_weak_this(__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __d(__p);
+ throw;
+ }
+#endif
+}
+
+template<class _Tp>
+template<class _Dp>
+shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
+ : __ptr_(0)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
+ {
+#endif
+ typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
+ __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __d(__p);
+ throw;
+ }
+#endif
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp, class _Alloc>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
+ : __ptr_(__p)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
+ {
+#endif
+ typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
+ typedef __allocator_destructor<_A2> _D2;
+ _A2 __a2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
+ __cntrl_ = __hold2.release();
+ __enable_weak_this(__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __d(__p);
+ throw;
+ }
+#endif
+}
+
+template<class _Tp>
+template<class _Dp, class _Alloc>
+shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
+ : __ptr_(0)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
+ {
+#endif
+ typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
+ typedef __allocator_destructor<_A2> _D2;
+ _A2 __a2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
+ __cntrl_ = __hold2.release();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __d(__p);
+ throw;
+ }
+#endif
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p)
+ : __ptr_(__p),
+ __cntrl_(__r.__cntrl_)
+{
+ if (__cntrl_)
+ __cntrl_->__add_shared();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ if (__cntrl_)
+ __cntrl_->__add_shared();
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ if (__cntrl_)
+ __cntrl_->__add_shared();
+}
+
+#ifdef _LIBCPP_MOVE
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ __r.__ptr_ = 0;
+ __r.__cntrl_ = 0;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ __r.__ptr_ = 0;
+ __r.__cntrl_ = 0;
+}
+
+#endif
+
+template<class _Tp>
+template<class _Yp>
+#ifdef _LIBCPP_MOVE
+shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
+#else
+shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>& __r)
+#endif
+ : __ptr_(__r.get())
+{
+ typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
+ __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
+ __enable_weak_this(__r.get());
+ __r.release();
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+#ifdef _LIBCPP_MOVE
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
+#else
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
+#endif
+ typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
+ : __ptr_(__r.get())
+{
+ typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
+ __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
+ __enable_weak_this(__r.get());
+ __r.release();
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+#ifdef _LIBCPP_MOVE
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
+#else
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
+#endif
+ typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
+ : __ptr_(__r.get())
+{
+ typedef __shared_ptr_pointer<_Yp*,
+ reference_wrapper<typename remove_reference<_Dp>::type>,
+ allocator<_Yp> > _CntrlBlk;
+ __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
+ __enable_weak_this(__r.get());
+ __r.release();
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+template<class ..._Args>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_Args&& ...__args)
+{
+ typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+ typedef allocator<_CntrlBlk> _A2;
+ typedef __allocator_destructor<_A2> _D2;
+ _A2 __a2;
+ unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class ..._Args>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
+{
+ typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
+ typedef __allocator_destructor<_A2> _D2;
+ _A2 __a2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__a, _STD::forward<_Args>(__args)...);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+#else // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared()
+{
+ typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+ typedef allocator<_CntrlBlk> _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2;
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__alloc2);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _A0>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_A0& __a0)
+{
+ typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+ typedef allocator<_CntrlBlk> _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2;
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _A0, class _A1>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
+{
+ typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+ typedef allocator<_CntrlBlk> _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2;
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _A0, class _A1, class _A2>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
+{
+ typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+ typedef allocator<_CntrlBlk> _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2;
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _Alloc>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
+{
+ typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__a);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class _A0>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
+{
+ typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__a, __a0);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class _A0, class _A1>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
+{
+ typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class _A0, class _A1, class _A2>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+ typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+ typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+ typedef __allocator_destructor<_Alloc2> _D2;
+ _Alloc2 __alloc2(__a);
+ unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+ ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
+ shared_ptr<_Tp> __r;
+ __r.__ptr_ = __hold2.get()->get();
+ __r.__cntrl_ = __hold2.release();
+ __r.__enable_weak_this(__r.__ptr_);
+ return __r;
+}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+shared_ptr<_Tp>::~shared_ptr()
+{
+ if (__cntrl_)
+ __cntrl_->__release_shared();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(const shared_ptr& __r)
+{
+ shared_ptr(__r).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r)
+{
+ shared_ptr(__r).swap(*this);
+ return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(shared_ptr&& __r)
+{
+ shared_ptr(_STD::move(__r)).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
+{
+ shared_ptr(_STD::move(__r)).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
+{
+ shared_ptr(__r).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
+{
+ shared_ptr(_STD::move(__r)).swap(*this);
+ return *this;
+}
+
+#else
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(auto_ptr<_Yp>& __r)
+{
+ shared_ptr(__r).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
+{
+ shared_ptr(_STD::move(__r)).swap(*this);
+ return *this;
+}
+
+#endif
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::swap(shared_ptr& __r)
+{
+ _STD::swap(__ptr_, __r.__ptr_);
+ _STD::swap(__cntrl_, __r.__cntrl_);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset()
+{
+ shared_ptr().swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset(_Yp* __p)
+{
+ shared_ptr(__p).swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
+{
+ shared_ptr(__p, __d).swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
+{
+ shared_ptr(__p, __d, __a).swap(*this);
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_Args&& ...__args)
+{
+ return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...);
+}
+
+template<class _Tp, class _Alloc, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _Args&& ...__args)
+{
+ return shared_ptr<_Tp>::allocate_shared(__a, _STD::forward<_Args>(__args)...);
+}
+
+#else // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared()
+{
+ return shared_ptr<_Tp>::make_shared();
+}
+
+template<class _Tp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_A0& __a0)
+{
+ return shared_ptr<_Tp>::make_shared(__a0);
+}
+
+template<class _Tp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_A0& __a0, _A1& __a1)
+{
+ return shared_ptr<_Tp>::make_shared(__a0, __a1);
+}
+
+template<class _Tp, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
+{
+ return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
+}
+
+template<class _Tp, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a)
+{
+ return shared_ptr<_Tp>::allocate_shared(__a);
+}
+
+template<class _Tp, class _Alloc, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _A0& __a0)
+{
+ return shared_ptr<_Tp>::allocate_shared(__a, __a0);
+}
+
+template<class _Tp, class _Alloc, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
+{
+ return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
+}
+
+template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+ return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
+}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y)
+{
+ return __x.get() == __y.get();
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y)
+{
+ return !(__x == __y);
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y)
+{
+ return __x.get() < __y.get();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y)
+{
+ __x.swap(__y);
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+static_pointer_cast(const shared_ptr<_Up>& __r)
+{
+ return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+dynamic_pointer_cast(const shared_ptr<_Up>& __r)
+{
+ _Tp* __p = dynamic_cast<_Tp*>(__r.get());
+ return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
+}
+
+template<class _Tp, class _Up>
+shared_ptr<_Tp>
+const_pointer_cast(const shared_ptr<_Up>& __r)
+{
+ return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get()));
+}
+
+template<class _Dp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Dp*
+get_deleter(const shared_ptr<_Tp>& __p)
+{
+ return __p.template __get_deleter<_Dp>();
+}
+
+template<class _Tp>
+class weak_ptr
+{
+public:
+ typedef _Tp element_type;
+private:
+ element_type* __ptr_;
+ __shared_weak_count* __cntrl_;
+
+public:
+ weak_ptr();
+ template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat());
+ weak_ptr(weak_ptr const& __r);
+ template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat());
+
+ ~weak_ptr();
+
+ weak_ptr& operator=(weak_ptr const& __r);
+ template<class _Yp> weak_ptr& operator=(weak_ptr<_Yp> const& __r);
+ template<class _Yp> weak_ptr& operator=(shared_ptr<_Yp> const& __r);
+
+ void swap(weak_ptr& __r);
+ void reset();
+
+ long use_count() const {return __cntrl_ ? __cntrl_->use_count() : 0;}
+ bool expired() const {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
+ shared_ptr<_Tp> lock() const;
+ template<class _Up> bool owner_before(const shared_ptr<_Up>& __r) const
+ {return __cntrl_ < __r.__cntrl_;}
+ template<class _Up> bool owner_before(const weak_ptr<_Up>& __r) const
+ {return __cntrl_ < __r.__cntrl_;}
+
+ template <class _Up> friend class weak_ptr;
+ template <class _Up> friend class shared_ptr;
+};
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr()
+ : __ptr_(0),
+ __cntrl_(0)
+{
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ if (__cntrl_)
+ __cntrl_->__add_weak();
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ if (__cntrl_)
+ __cntrl_->__add_weak();
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ if (__cntrl_)
+ __cntrl_->__add_weak();
+}
+
+template<class _Tp>
+weak_ptr<_Tp>::~weak_ptr()
+{
+ if (__cntrl_)
+ __cntrl_->__release_weak();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(weak_ptr const& __r)
+{
+ weak_ptr(__r).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r)
+{
+ weak_ptr(__r).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r)
+{
+ weak_ptr(__r).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+weak_ptr<_Tp>::swap(weak_ptr& __r)
+{
+ _STD::swap(__ptr_, __r.__ptr_);
+ _STD::swap(__cntrl_, __r.__cntrl_);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y)
+{
+ __x.swap(__y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+weak_ptr<_Tp>::reset()
+{
+ weak_ptr().swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp>
+shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
+{
+ if (__cntrl_ == 0)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ throw bad_weak_ptr();
+#else
+ assert(!"bad_weak_ptr");
+#endif
+}
+
+template<class _Tp>
+shared_ptr<_Tp>
+weak_ptr<_Tp>::lock() const
+{
+ shared_ptr<_Tp> __r;
+ __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
+ if (__r.__cntrl_)
+ __r.__ptr_ = __ptr_;
+ return __r;
+}
+
+template <class _Tp> struct owner_less;
+
+template <class _Tp>
+struct owner_less<shared_ptr<_Tp> >
+ : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
+{
+ typedef bool result_type;
+ bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+ {return __x.owner_before(__y);}
+ bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
+ {return __x.owner_before(__y);}
+ bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+ {return __x.owner_before(__y);}
+};
+
+template <class _Tp>
+struct owner_less<weak_ptr<_Tp> >
+ : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
+{
+ typedef bool result_type;
+ bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
+ {return __x.owner_before(__y);}
+ bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
+ {return __x.owner_before(__y);}
+ bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+ {return __x.owner_before(__y);}
+};
+
+template<class _Tp>
+class enable_shared_from_this
+{
+ mutable weak_ptr<_Tp> __weak_this_;
+protected:
+ enable_shared_from_this() {}
+ enable_shared_from_this(enable_shared_from_this const&) {}
+ enable_shared_from_this& operator=(enable_shared_from_this const&) {return *this;}
+ ~enable_shared_from_this() {}
+public:
+ shared_ptr<_Tp> shared_from_this() {return shared_ptr<_Tp>(__weak_this_);}
+ shared_ptr<_Tp const> shared_from_this() const {return shared_ptr<const _Tp>(__weak_this_);}
+
+ template <class _Up> friend class shared_ptr;
+};
+
+//enum class
+struct pointer_safety
+{
+ enum _
+ {
+ relaxed,
+ preferred,
+ strict
+ };
+
+ _ __v_;
+
+ pointer_safety(_ __v) : __v_(__v) {}
+ operator int() const {return __v_;}
+};
+
+void declare_reachable(void* __p);
+void declare_no_pointers(char* __p, size_t __n);
+void undeclare_no_pointers(char* __p, size_t __n);
+pointer_safety get_pointer_safety();
+void* __undeclare_reachable(void*);
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+undeclare_reachable(_Tp* __p)
+{
+ return static_cast<_Tp*>(__undeclare_reachable(__p));
+}
+
+void* align(size_t, size_t, void*&, size_t&);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_MEMORY
+
+// hh 060228 Created