// -*- 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 struct uses_allocator; template struct pointer_traits { typedef Ptr pointer; typedef
element_type; typedef
difference_type; template using rebind =
; static pointer pointer_to(
); }; template 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::rebind const_pointer; typedef Alloc::void_pointer | pointer_traits::rebind void_pointer; typedef Alloc::const_void_pointer | pointer_traits::rebind 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 using rebind_alloc = Alloc::rebind::other | Alloc; template using rebind_traits = allocator_traits>; 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 static void construct(allocator_type& a, T* p, Args&&... args); template 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 { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind {typedef allocator<_Up> other;}; }; template 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::type reference; typedef typename add_lvalue_reference::type const_reference; typedef T value_type; template struct rebind {typedef allocator other;}; allocator() throw(); allocator(const allocator&) throw(); template allocator(const allocator&) throw(); ~allocator() throw(); pointer address(reference x) const; const_pointer address(const_reference x) const; pointer allocate(size_type, allocator::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 bool operator==(const allocator&, const allocator&) throw(); template bool operator!=(const allocator&, const allocator&) throw(); template class raw_storage_iterator : public 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 pair get_temporary_buffer(ptrdiff_t n); template void return_temporary_buffer(T* p); template ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); template void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); template void uninitialized_fill_n(ForwardIterator first, Size n, const T& x); template struct auto_ptr_ref {}; template class auto_ptr { public: typedef X element_type; explicit auto_ptr(X* p =0) throw(); auto_ptr(auto_ptr&) throw(); template auto_ptr(auto_ptr&) throw(); auto_ptr& operator=(auto_ptr&) throw(); template auto_ptr& operator=(auto_ptr&) throw(); auto_ptr& operator=(auto_ptr_ref r) throw(); ~auto_ptr() throw(); typename add_lvalue_reference::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) throw(); template operator auto_ptr_ref() throw(); template operator auto_ptr() throw(); }; template struct default_delete { constexpr default_delete(); template default_delete(const default_delete&); void operator()(T*) const; }; template struct default_delete { constexpr default_delete(); void operator()(T*) const; template void operator()(U*) const = delete; }; template > class unique_ptr; template > class unique_ptr { public: typedef see below pointer; typedef T element_type; typedef D deleter_type; // constructors constexpr unique_ptr(); explicit unique_ptr(pointer p); unique_ptr(pointer p, implementation-defined d1); unique_ptr(pointer p, implementation-defined d2); unique_ptr(unique_ptr&& u); unique_ptr(nullptr_t) : unique_ptr() { } template unique_ptr(unique_ptr&& u); template unique_ptr(auto_ptr&& u); // destructor ~unique_ptr(); // assignment unique_ptr& operator=(unique_ptr&& u); template unique_ptr& operator=(unique_ptr&& u); unique_ptr& operator=(nullptr_t); // observers typename add_lvalue_reference::type operator*() const; pointer operator->() const; pointer get() const; deleter_type& get_deleter(); const deleter_type& get_deleter() const; explicit operator bool() const; // modifiers pointer release(); void reset(pointer p = pointer()); void swap(unique_ptr& u); }; template class unique_ptr { public: typedef implementation-defined pointer; typedef T element_type; typedef D deleter_type; // constructors constexpr unique_ptr(); explicit unique_ptr(pointer p); unique_ptr(pointer p, implementation-defined d); unique_ptr(pointer p, implementation-defined d); unique_ptr(unique_ptr&& u); unique_ptr(nullptr_t) : unique_ptr() { } // destructor ~unique_ptr(); // assignment unique_ptr& operator=(unique_ptr&& u); unique_ptr& operator=(nullptr_t); // observers T& operator[](size_t i) const; pointer get() const; deleter_type& get_deleter(); const deleter_type& get_deleter() const; explicit operator bool() const; // modifiers pointer release(); void reset(pointer p = pointer()); void reset(nullptr_t); template void reset(U) = delete; void swap(unique_ptr& u); }; template void swap(unique_ptr& x, unique_ptr& y); template bool operator==(const unique_ptr& x, const unique_ptr& y); template bool operator!=(const unique_ptr& x, const unique_ptr& y); template bool operator<(const unique_ptr& x, const unique_ptr& y); template bool operator<=(const unique_ptr& x, const unique_ptr& y); template bool operator>(const unique_ptr& x, const unique_ptr& y); template bool operator>=(const unique_ptr& x, const unique_ptr& y); class bad_weak_ptr : public std::exception { bad_weak_ptr(); }; template class shared_ptr { public: typedef T element_type; // constructors: constexpr shared_ptr(); template explicit shared_ptr(Y* p); template shared_ptr(Y* p, D d); template shared_ptr(Y* p, D d, A a); template shared_ptr(nullptr_t p, D d); template shared_ptr(nullptr_t p, D d, A a); template shared_ptr(const shared_ptr& r, T *p); shared_ptr(const shared_ptr& r); template shared_ptr(const shared_ptr& r); shared_ptr(shared_ptr&& r); template shared_ptr(shared_ptr&& r); template explicit shared_ptr(const weak_ptr& r); template shared_ptr(auto_ptr&& r); template shared_ptr(unique_ptr&& r); shared_ptr(nullptr_t) : shared_ptr() { } // destructor: ~shared_ptr(); // assignment: shared_ptr& operator=(const shared_ptr& r); template shared_ptr& operator=(const shared_ptr& r); shared_ptr& operator=(shared_ptr&& r); template shared_ptr& operator=(shared_ptr&& r); template shared_ptr& operator=(auto_ptr&& r); template shared_ptr& operator=(unique_ptr&& r); // modifiers: void swap(shared_ptr& r); void reset(); template void reset(Y* p); template void reset(Y* p, D d); template void reset(Y* p, D d, A a); // observers: T* get() const; T& operator*() const; T* operator->() const; long use_count() const; bool unique() const; explicit operator bool() const; template bool owner_before(shared_ptr const& b) const; template bool owner_before(weak_ptr const& b) const; }; // shared_ptr comparisons: template bool operator==(shared_ptr const& a, shared_ptr const& b); template bool operator!=(shared_ptr const& a, shared_ptr const& b); template bool operator<(shared_ptr const& a, shared_ptr const& b); template bool operator>(shared_ptr const& a, shared_ptr const& b); template bool operator<=(shared_ptr const& a, shared_ptr const& b); template bool operator>=(shared_ptr const& a, shared_ptr const& b); // shared_ptr specialized algorithms: template void swap(shared_ptr& a, shared_ptr& b); // shared_ptr casts: template shared_ptr static_pointer_cast(shared_ptr const& r); template shared_ptr dynamic_pointer_cast(shared_ptr const& r); template shared_ptr const_pointer_cast(shared_ptr const& r); // shared_ptr I/O: template basic_ostream& operator<< (basic_ostream& os, shared_ptr const& p); // shared_ptr get_deleter: template D* get_deleter(shared_ptr const& p); template shared_ptr make_shared(Args&&... args); template shared_ptr allocate_shared(const A& a, Args&&... args); template class weak_ptr { public: typedef T element_type; // constructors constexpr weak_ptr(); template weak_ptr(shared_ptr const& r); weak_ptr(weak_ptr const& r); template weak_ptr(weak_ptr const& r); // destructor ~weak_ptr(); // assignment weak_ptr& operator=(weak_ptr const& r); template weak_ptr& operator=(weak_ptr const& r); template weak_ptr& operator=(shared_ptr const& r); // modifiers void swap(weak_ptr& r); void reset(); // observers long use_count() const; bool expired() const; shared_ptr lock() const; template bool owner_before(shared_ptr const& b); template bool owner_before(weak_ptr const& b); }; // weak_ptr specialized algorithms: template void swap(weak_ptr& a, weak_ptr& b); // class owner_less: template struct owner_less; template struct owner_less> : binary_function, shared_ptr, bool> { typedef bool result_type; bool operator()(shared_ptr const&, shared_ptr const&) const; bool operator()(shared_ptr const&, weak_ptr const&) const; bool operator()(weak_ptr const&, shared_ptr const&) const; }; template struct owner_less> : binary_function, weak_ptr, bool> { typedef bool result_type; bool operator()(weak_ptr const&, weak_ptr const&) const; bool operator()(shared_ptr const&, weak_ptr const&) const; bool operator()(weak_ptr const&, shared_ptr const&) const; }; template class enable_shared_from_this { protected: constexpr enable_shared_from_this(); enable_shared_from_this(enable_shared_from_this const&); enable_shared_from_this& operator=(enable_shared_from_this const&); ~enable_shared_from_this(); public: shared_ptr shared_from_this(); shared_ptr shared_from_this() const; }; template bool atomic_is_lock_free(const shared_ptr* p); template shared_ptr atomic_load(const shared_ptr* p); template shared_ptr atomic_load_explicit(const shared_ptr* p, memory_order mo); template void atomic_store(shared_ptr* p, shared_ptr r); template void atomic_store_explicit(shared_ptr* p, shared_ptr r, memory_order mo); template shared_ptr atomic_exchange(shared_ptr* p, shared_ptr r); template shared_ptr atomic_exchange_explicit(shared_ptr* p, shared_ptr r, memory_order mo); template bool atomic_compare_exchange_weak(shared_ptr* p, shared_ptr* v, shared_ptr w); template bool atomic_compare_exchange_strong( shared_ptr* p, shared_ptr* v, shared_ptr w); template bool atomic_compare_exchange_weak_explicit(shared_ptr* p, shared_ptr* v, shared_ptr w, memory_order success, memory_order failure); template bool atomic_compare_exchange_strong_explicit(shared_ptr* p, shared_ptr* v, shared_ptr w, memory_order success, memory_order failure); // Hash support template struct hash; template struct hash >; template struct hash >; // Pointer safety enum class pointer_safety { relaxed, preferred, strict }; void declare_reachable(void *p); template T *undeclare_reachable(T *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* align(size_t alignment, size_t size, void*& ptr, size_t& space); } // std */ #include <__config> #include #include #include #include #include #include #include #include #include <__functional_base> #if defined(_LIBCPP_NO_EXCEPTIONS) #include #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 inline _LIBCPP_INLINE_VISIBILITY _Tp* addressof(_Tp& __x) { return (_Tp*)&(char&)__x; } template class allocator; template <> class allocator { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind {typedef allocator<_Up> other;}; }; // pointer_traits template struct __has_element_type { private: struct __two {char _; char __;}; template static __two __test(...); template static char __test(typename _Up::element_type* = 0); public: static const bool value = sizeof(__test<_Tp>(0)) == 1; }; template ::value> struct __pointer_traits_element_type; template struct __pointer_traits_element_type<_Ptr, true> { typedef typename _Ptr::element_type type; }; #ifndef _LIBCPP_HAS_NO_VARIADICS template