2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===-------------------------- memory ------------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_MEMORY
|
|
|
|
#define _LIBCPP_MEMORY
|
|
|
|
|
|
|
|
/*
|
|
|
|
memory synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
struct allocator_arg_t { };
|
2018-01-03 01:17:01 +08:00
|
|
|
inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class U> using rebind = <details>;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
static pointer pointer_to(<details>);
|
|
|
|
};
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
template <class T>
|
|
|
|
struct pointer_traits<T*>
|
|
|
|
{
|
|
|
|
typedef T* pointer;
|
|
|
|
typedef T element_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
|
|
|
|
template <class U> using rebind = U*;
|
|
|
|
|
2018-11-14 01:04:05 +08:00
|
|
|
static pointer pointer_to(<details>) noexcept; // constexpr in C++20
|
2011-05-28 22:41:13 +08:00
|
|
|
};
|
|
|
|
|
2017-11-23 03:49:21 +08:00
|
|
|
template <class T> constexpr T* to_address(T* p) noexcept; // C++20
|
|
|
|
template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
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
|
2010-11-18 09:40:00 +08:00
|
|
|
| pointer_traits<pointer>::difference_type
|
|
|
|
difference_type;
|
|
|
|
typedef Alloc::size_type
|
|
|
|
| make_unsigned<difference_type>::type
|
|
|
|
size_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
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;
|
2015-06-03 00:34:03 +08:00
|
|
|
typedef Alloc::is_always_equal
|
|
|
|
| is_empty is_always_equal;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
|
|
|
|
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
|
|
|
|
2017-11-26 10:55:38 +08:00
|
|
|
static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
|
|
|
|
static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-08-28 04:22:15 +08:00
|
|
|
static size_type max_size(const allocator_type& a); // noexcept in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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;};
|
|
|
|
|
2018-03-21 07:02:53 +08:00
|
|
|
constexpr allocator() noexcept; // constexpr in C++20
|
|
|
|
constexpr allocator(const allocator&) noexcept; // constexpr in C++20
|
|
|
|
template <class U>
|
|
|
|
constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
|
2011-05-28 22:41:13 +08:00
|
|
|
~allocator();
|
|
|
|
pointer address(reference x) const noexcept;
|
|
|
|
const_pointer address(const_reference x) const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
|
2011-05-28 22:41:13 +08:00
|
|
|
void deallocate(pointer p, size_type n) noexcept;
|
|
|
|
size_type max_size() const noexcept;
|
|
|
|
template<class U, class... Args>
|
|
|
|
void construct(U* p, Args&&... args);
|
|
|
|
template <class U>
|
|
|
|
void destroy(U* p);
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
|
|
|
|
template <class T> void return_temporary_buffer(T* p) noexcept;
|
|
|
|
|
|
|
|
template <class T> T* addressof(T& r) noexcept;
|
2016-11-15 02:22:19 +08:00
|
|
|
template <class T> T* addressof(const T&& r) noexcept = delete;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class InputIterator, class ForwardIterator>
|
|
|
|
ForwardIterator
|
|
|
|
uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
template <class InputIterator, class Size, class ForwardIterator>
|
|
|
|
ForwardIterator
|
|
|
|
uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class ForwardIterator, class T>
|
|
|
|
void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
|
|
|
|
|
|
|
|
template <class ForwardIterator, class Size, class T>
|
2010-11-19 00:13:03 +08:00
|
|
|
ForwardIterator
|
|
|
|
uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 11:51:39 +08:00
|
|
|
template <class T>
|
|
|
|
void destroy_at(T* location);
|
|
|
|
|
|
|
|
template <class ForwardIterator>
|
|
|
|
void destroy(ForwardIterator first, ForwardIterator last);
|
|
|
|
|
|
|
|
template <class ForwardIterator, class Size>
|
|
|
|
ForwardIterator destroy_n(ForwardIterator first, Size n);
|
|
|
|
|
|
|
|
template <class InputIterator, class ForwardIterator>
|
|
|
|
ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
|
|
|
|
|
|
|
|
template <class InputIterator, class Size, class ForwardIterator>
|
|
|
|
pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
|
|
|
|
|
|
|
|
template <class ForwardIterator>
|
|
|
|
void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
|
|
|
|
|
|
|
|
template <class ForwardIterator, class Size>
|
|
|
|
ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
|
|
|
|
|
|
|
|
template <class ForwardIterator>
|
|
|
|
void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
|
|
|
|
|
|
|
|
template <class ForwardIterator, class Size>
|
|
|
|
ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
|
|
|
|
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class X>
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
class auto_ptr // deprecated in C++11, removed in C++17
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class T>
|
|
|
|
struct default_delete
|
|
|
|
{
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr default_delete() noexcept = default;
|
|
|
|
template <class U> default_delete(const default_delete<U>&) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
void operator()(T*) const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct default_delete<T[]>
|
|
|
|
{
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr default_delete() noexcept = default;
|
|
|
|
void operator()(T*) const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class U> void operator()(U*) const = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class D = default_delete<T>>
|
|
|
|
class unique_ptr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef see below pointer;
|
|
|
|
typedef T element_type;
|
|
|
|
typedef D deleter_type;
|
|
|
|
|
|
|
|
// constructors
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr unique_ptr() noexcept;
|
|
|
|
explicit unique_ptr(pointer p) noexcept;
|
|
|
|
unique_ptr(pointer p, see below d1) noexcept;
|
|
|
|
unique_ptr(pointer p, see below d2) noexcept;
|
|
|
|
unique_ptr(unique_ptr&& u) noexcept;
|
|
|
|
unique_ptr(nullptr_t) noexcept : unique_ptr() { }
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class U, class E>
|
2011-05-28 22:41:13 +08:00
|
|
|
unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class U>
|
2017-01-25 06:22:33 +08:00
|
|
|
unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// destructor
|
|
|
|
~unique_ptr();
|
|
|
|
|
|
|
|
// assignment
|
2011-05-28 22:41:13 +08:00
|
|
|
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
|
|
|
template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
|
|
|
unique_ptr& operator=(nullptr_t) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// observers
|
|
|
|
typename add_lvalue_reference<T>::type operator*() const;
|
2011-05-28 22:41:13 +08:00
|
|
|
pointer operator->() const noexcept;
|
|
|
|
pointer get() const noexcept;
|
|
|
|
deleter_type& get_deleter() noexcept;
|
|
|
|
const deleter_type& get_deleter() const noexcept;
|
|
|
|
explicit operator bool() const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// modifiers
|
2011-05-28 22:41:13 +08:00
|
|
|
pointer release() noexcept;
|
|
|
|
void reset(pointer p = pointer()) noexcept;
|
|
|
|
void swap(unique_ptr& u) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class D>
|
|
|
|
class unique_ptr<T[], D>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef implementation-defined pointer;
|
|
|
|
typedef T element_type;
|
|
|
|
typedef D deleter_type;
|
|
|
|
|
|
|
|
// constructors
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr unique_ptr() noexcept;
|
|
|
|
explicit unique_ptr(pointer p) noexcept;
|
|
|
|
unique_ptr(pointer p, see below d) noexcept;
|
|
|
|
unique_ptr(pointer p, see below d) noexcept;
|
|
|
|
unique_ptr(unique_ptr&& u) noexcept;
|
|
|
|
unique_ptr(nullptr_t) noexcept : unique_ptr() { }
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// destructor
|
2010-08-22 08:02:43 +08:00
|
|
|
~unique_ptr();
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// assignment
|
2011-05-28 22:41:13 +08:00
|
|
|
unique_ptr& operator=(unique_ptr&& u) noexcept;
|
|
|
|
unique_ptr& operator=(nullptr_t) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// observers
|
|
|
|
T& operator[](size_t i) const;
|
2011-05-28 22:41:13 +08:00
|
|
|
pointer get() const noexcept;
|
|
|
|
deleter_type& get_deleter() noexcept;
|
|
|
|
const deleter_type& get_deleter() const noexcept;
|
|
|
|
explicit operator bool() const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// modifiers
|
2011-05-28 22:41:13 +08:00
|
|
|
pointer release() noexcept;
|
|
|
|
void reset(pointer p = pointer()) noexcept;
|
|
|
|
void reset(nullptr_t) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class U> void reset(U) = delete;
|
2011-05-28 22:41:13 +08:00
|
|
|
void swap(unique_ptr& u) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class D>
|
2011-05-28 22:41:13 +08:00
|
|
|
void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class T1, class D1, class T2, class D2>
|
|
|
|
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
template <class T1, class D1, class T2, class D2>
|
|
|
|
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
template <class T1, class D1, class T2, class D2>
|
|
|
|
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
template <class T1, class D1, class T2, class D2>
|
|
|
|
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
template <class T1, class D1, class T2, class D2>
|
|
|
|
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
template <class T1, class D1, class T2, class D2>
|
|
|
|
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
template <class T, class D>
|
|
|
|
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
|
|
|
|
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator<(nullptr_t, const unique_ptr<T, D>& y);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator>(nullptr_t, const unique_ptr<T, D>& y);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
|
|
|
|
template <class T, class D>
|
|
|
|
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
class bad_weak_ptr
|
|
|
|
: public std::exception
|
|
|
|
{
|
2011-05-28 22:41:13 +08:00
|
|
|
bad_weak_ptr() noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
2013-07-02 02:16:03 +08:00
|
|
|
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
|
|
|
|
template<class T> unique_ptr<T> make_unique(size_t n); // C++14
|
|
|
|
template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
|
|
|
|
|
2017-11-27 23:51:36 +08:00
|
|
|
template<class E, class T, class Y, class D>
|
|
|
|
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T>
|
|
|
|
class shared_ptr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T element_type;
|
2016-06-27 09:02:43 +08:00
|
|
|
typedef weak_ptr<T> weak_type; // C++17
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// constructors:
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr shared_ptr() noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class Y> explicit shared_ptr(Y* p);
|
|
|
|
template<class Y, class D> shared_ptr(Y* p, D d);
|
|
|
|
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
|
|
|
template <class D> shared_ptr(nullptr_t p, D d);
|
|
|
|
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
|
2011-05-28 22:41:13 +08:00
|
|
|
template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
|
|
|
|
shared_ptr(const shared_ptr& r) noexcept;
|
|
|
|
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
|
|
|
|
shared_ptr(shared_ptr&& r) noexcept;
|
|
|
|
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
2017-01-25 06:22:33 +08:00
|
|
|
template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
|
|
|
|
shared_ptr(nullptr_t) : shared_ptr() { }
|
|
|
|
|
|
|
|
// destructor:
|
|
|
|
~shared_ptr();
|
|
|
|
|
|
|
|
// assignment:
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr& operator=(const shared_ptr& r) noexcept;
|
|
|
|
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
|
|
|
|
shared_ptr& operator=(shared_ptr&& r) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
|
2017-01-25 06:22:33 +08:00
|
|
|
template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
|
|
|
|
|
|
|
|
// modifiers:
|
2011-05-28 22:41:13 +08:00
|
|
|
void swap(shared_ptr& r) noexcept;
|
|
|
|
void reset() noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class Y> void reset(Y* p);
|
|
|
|
template<class Y, class D> void reset(Y* p, D d);
|
|
|
|
template<class Y, class D, class A> void reset(Y* p, D d, A a);
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
// observers:
|
|
|
|
T* get() const noexcept;
|
|
|
|
T& operator*() const noexcept;
|
|
|
|
T* operator->() const noexcept;
|
|
|
|
long use_count() const noexcept;
|
|
|
|
bool unique() const noexcept;
|
|
|
|
explicit operator bool() const noexcept;
|
2017-04-12 01:08:53 +08:00
|
|
|
template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
|
|
|
|
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// shared_ptr comparisons:
|
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
|
|
|
|
template <class T>
|
|
|
|
bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// shared_ptr specialized algorithms:
|
2011-05-28 22:41:13 +08:00
|
|
|
template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// shared_ptr casts:
|
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template<class T, class U>
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// shared_ptr I/O:
|
|
|
|
template<class E, class T, class Y>
|
|
|
|
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
|
|
|
|
|
|
|
|
// shared_ptr get_deleter:
|
2011-05-28 22:41:13 +08:00
|
|
|
template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template<class T, class... Args>
|
|
|
|
shared_ptr<T> make_shared(Args&&... args);
|
|
|
|
template<class T, class A, class... Args>
|
|
|
|
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class weak_ptr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T element_type;
|
|
|
|
|
|
|
|
// constructors
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr weak_ptr() noexcept;
|
|
|
|
template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
|
|
|
|
weak_ptr(weak_ptr const& r) noexcept;
|
|
|
|
template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
|
2014-03-05 11:12:04 +08:00
|
|
|
weak_ptr(weak_ptr&& r) noexcept; // C++14
|
|
|
|
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// destructor
|
|
|
|
~weak_ptr();
|
|
|
|
|
|
|
|
// assignment
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr& operator=(weak_ptr const& r) noexcept;
|
|
|
|
template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
|
|
|
|
template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
|
2014-03-05 11:12:04 +08:00
|
|
|
weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
|
|
|
|
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// modifiers
|
2011-05-28 22:41:13 +08:00
|
|
|
void swap(weak_ptr& r) noexcept;
|
|
|
|
void reset() noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// observers
|
2011-05-28 22:41:13 +08:00
|
|
|
long use_count() const noexcept;
|
|
|
|
bool expired() const noexcept;
|
|
|
|
shared_ptr<T> lock() const noexcept;
|
2017-04-12 01:08:53 +08:00
|
|
|
template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
|
|
|
|
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// weak_ptr specialized algorithms:
|
2011-05-28 22:41:13 +08:00
|
|
|
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// class owner_less:
|
|
|
|
template<class T> struct owner_less;
|
|
|
|
|
|
|
|
template<class T>
|
2019-06-24 04:47:21 +08:00
|
|
|
struct owner_less<shared_ptr<T> >
|
2010-08-20 02:39:17 +08:00
|
|
|
: binary_function<shared_ptr<T>, shared_ptr<T>, bool>
|
|
|
|
{
|
|
|
|
typedef bool result_type;
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
|
|
|
|
bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
|
|
|
|
bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2019-06-24 04:47:21 +08:00
|
|
|
struct owner_less<weak_ptr<T> >
|
2010-08-20 02:39:17 +08:00
|
|
|
: binary_function<weak_ptr<T>, weak_ptr<T>, bool>
|
|
|
|
{
|
|
|
|
typedef bool result_type;
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
|
|
|
|
bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
|
|
|
|
bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> // Added in C++14
|
|
|
|
struct owner_less<void>
|
|
|
|
{
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
|
|
|
|
|
|
|
|
typedef void is_transparent;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class enable_shared_from_this
|
|
|
|
{
|
|
|
|
protected:
|
2011-05-28 22:41:13 +08:00
|
|
|
constexpr enable_shared_from_this() noexcept;
|
|
|
|
enable_shared_from_this(enable_shared_from_this const&) noexcept;
|
|
|
|
enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
~enable_shared_from_this();
|
|
|
|
public:
|
|
|
|
shared_ptr<T> shared_from_this();
|
|
|
|
shared_ptr<T const> shared_from_this() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
bool atomic_is_lock_free(const shared_ptr<T>* p);
|
|
|
|
template<class T>
|
|
|
|
shared_ptr<T> atomic_load(const shared_ptr<T>* p);
|
|
|
|
template<class T>
|
|
|
|
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
|
|
|
|
template<class T>
|
|
|
|
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
|
|
|
|
template<class T>
|
|
|
|
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
|
|
|
template<class T>
|
|
|
|
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
|
|
|
|
template<class T>
|
|
|
|
shared_ptr<T>
|
|
|
|
atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
|
|
|
|
shared_ptr<T> w, memory_order success,
|
|
|
|
memory_order failure);
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
|
|
|
|
shared_ptr<T> w, memory_order success,
|
|
|
|
memory_order failure);
|
|
|
|
// Hash support
|
|
|
|
template <class T> struct hash;
|
|
|
|
template <class T, class D> struct hash<unique_ptr<T, D> >;
|
|
|
|
template <class T> struct hash<shared_ptr<T> >;
|
|
|
|
|
2018-01-03 01:17:01 +08:00
|
|
|
template <class T, class Alloc>
|
|
|
|
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
// Pointer safety
|
|
|
|
enum class pointer_safety { relaxed, preferred, strict };
|
|
|
|
void declare_reachable(void *p);
|
|
|
|
template <class T> T *undeclare_reachable(T *p);
|
|
|
|
void declare_no_pointers(char *p, size_t n);
|
|
|
|
void undeclare_no_pointers(char *p, size_t n);
|
2011-05-28 22:41:13 +08:00
|
|
|
pointer_safety get_pointer_safety() noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
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>
|
2011-07-18 23:51:59 +08:00
|
|
|
#include <iosfwd>
|
2011-12-20 01:58:44 +08:00
|
|
|
#include <tuple>
|
2016-05-07 11:12:24 +08:00
|
|
|
#include <stdexcept>
|
2012-02-15 08:41:34 +08:00
|
|
|
#include <cstring>
|
2015-08-20 01:21:46 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
|
2012-07-30 09:40:57 +08:00
|
|
|
# include <atomic>
|
|
|
|
#endif
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2012-07-30 09:40:57 +08:00
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2015-07-07 08:27:16 +08:00
|
|
|
template <class _ValueType>
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2015-07-07 08:27:16 +08:00
|
|
|
_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
|
|
|
|
defined(__ATOMIC_RELAXED) && \
|
2019-04-26 04:02:10 +08:00
|
|
|
(__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
|
2015-07-07 08:27:16 +08:00
|
|
|
return __atomic_load_n(__value, __ATOMIC_RELAXED);
|
|
|
|
#else
|
|
|
|
return *__value;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-04 17:55:12 +08:00
|
|
|
template <class _ValueType>
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-09-04 17:55:12 +08:00
|
|
|
_ValueType __libcpp_acquire_load(_ValueType const* __value) {
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
|
|
|
|
defined(__ATOMIC_ACQUIRE) && \
|
2019-04-26 04:02:10 +08:00
|
|
|
(__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
|
2016-09-04 17:55:12 +08:00
|
|
|
return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
|
|
|
|
#else
|
|
|
|
return *__value;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-15 02:22:19 +08:00
|
|
|
// addressof moved to <type_traits>
|
2011-06-23 06:17:44 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp> class allocator;
|
|
|
|
|
|
|
|
template <>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS allocator<void>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void* pointer;
|
|
|
|
typedef const void* const_pointer;
|
|
|
|
typedef void value_type;
|
|
|
|
|
|
|
|
template <class _Up> struct rebind {typedef allocator<_Up> other;};
|
|
|
|
};
|
|
|
|
|
2012-01-20 07:15:22 +08:00
|
|
|
template <>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS allocator<const void>
|
2012-01-20 07:15:22 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const void* pointer;
|
|
|
|
typedef const void* const_pointer;
|
|
|
|
typedef const void value_type;
|
|
|
|
|
|
|
|
template <class _Up> struct rebind {typedef allocator<_Up> other;};
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// pointer_traits
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_element_type : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_element_type<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::element_type>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Ptr, bool = __has_element_type<_Ptr>::value>
|
|
|
|
struct __pointer_traits_element_type;
|
|
|
|
|
|
|
|
template <class _Ptr>
|
|
|
|
struct __pointer_traits_element_type<_Ptr, true>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
|
|
|
|
template <template <class, class...> class _Sp, class _Tp, class ..._Args>
|
|
|
|
struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <template <class, class...> class _Sp, class _Tp, class ..._Args>
|
|
|
|
struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE _Tp type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_difference_type : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_difference_type<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::difference_type>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
|
|
|
|
struct __pointer_traits_difference_type
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Ptr>
|
|
|
|
struct __pointer_traits_difference_type<_Ptr, true>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
struct __has_rebind
|
|
|
|
{
|
|
|
|
private:
|
2012-10-31 03:06:59 +08:00
|
|
|
struct __two {char __lx; char __lxx;};
|
2010-05-12 03:42:16 +08:00
|
|
|
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
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#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>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#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;
|
|
|
|
};
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <template <class> class _Sp, class _Tp, class _Up>
|
|
|
|
struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
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>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
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>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
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>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Ptr>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS pointer_traits
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef _Ptr pointer;
|
|
|
|
typedef typename __pointer_traits_element_type<pointer>::type element_type;
|
|
|
|
typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-05-12 04:21:19 +08:00
|
|
|
template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
|
|
|
template <class _Up> struct rebind
|
|
|
|
{typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
|
2016-09-25 11:34:28 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct __nat {};
|
|
|
|
public:
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static pointer pointer_to(typename conditional<is_void<element_type>::value,
|
|
|
|
__nat, element_type>::type& __r)
|
|
|
|
{return pointer::pointer_to(__r);}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef _Tp* pointer;
|
|
|
|
typedef _Tp element_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Up> using rebind = _Up*;
|
|
|
|
#else
|
|
|
|
template <class _Up> struct rebind {typedef _Up* other;};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct __nat {};
|
|
|
|
public:
|
2018-11-14 01:04:05 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2010-05-12 03:42:16 +08:00
|
|
|
static pointer pointer_to(typename conditional<is_void<element_type>::value,
|
2011-05-28 22:41:13 +08:00
|
|
|
__nat, element_type>::type& __r) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
{return _VSTD::addressof(__r);}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2015-08-23 10:56:05 +08:00
|
|
|
template <class _From, class _To>
|
|
|
|
struct __rebind_pointer {
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2015-08-23 10:56:05 +08:00
|
|
|
typedef typename pointer_traits<_From>::template rebind<_To> type;
|
|
|
|
#else
|
|
|
|
typedef typename pointer_traits<_From>::template rebind<_To>::other type;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// allocator_traits
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_pointer_type : false_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_pointer_type<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::pointer>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
namespace __pointer_type_imp
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
|
|
|
|
struct __pointer_type
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Dp>
|
|
|
|
struct __pointer_type<_Tp, _Dp, false>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE _Tp* type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-11-18 09:40:00 +08:00
|
|
|
} // __pointer_type_imp
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Dp>
|
|
|
|
struct __pointer_type
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_const_pointer : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_const_pointer<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
|
|
|
|
struct __const_pointer
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Ptr, class _Alloc>
|
|
|
|
struct __const_pointer<_Tp, _Ptr, _Alloc, false>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
|
|
|
typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_void_pointer : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_void_pointer<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
|
|
|
|
struct __void_pointer
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Ptr, class _Alloc>
|
|
|
|
struct __void_pointer<_Ptr, _Alloc, false>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_const_void_pointer : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_const_void_pointer<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
|
|
|
|
struct __const_void_pointer
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Ptr, class _Alloc>
|
|
|
|
struct __const_void_pointer<_Ptr, _Alloc, false>
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type;
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Tp>
|
2017-11-23 03:49:21 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2011-11-30 02:15:50 +08:00
|
|
|
_Tp*
|
|
|
|
__to_raw_pointer(_Tp* __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return __p;
|
|
|
|
}
|
|
|
|
|
2017-11-23 03:49:21 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 17
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Pointer>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename pointer_traits<_Pointer>::element_type*
|
2011-05-28 22:41:13 +08:00
|
|
|
__to_raw_pointer(_Pointer __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
return _VSTD::__to_raw_pointer(__p.operator->());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
2017-11-23 03:49:21 +08:00
|
|
|
#else
|
|
|
|
template <class _Pointer>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
auto
|
|
|
|
__to_raw_pointer(const _Pointer& __p) _NOEXCEPT
|
|
|
|
-> decltype(pointer_traits<_Pointer>::to_address(__p))
|
|
|
|
{
|
|
|
|
return pointer_traits<_Pointer>::to_address(__p);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Pointer, class... _None>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
auto
|
|
|
|
__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return _VSTD::__to_raw_pointer(__p.operator->());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY constexpr
|
|
|
|
_Tp*
|
|
|
|
to_address(_Tp* __p) _NOEXCEPT
|
|
|
|
{
|
|
|
|
static_assert(!is_function_v<_Tp>, "_Tp is a function type");
|
|
|
|
return __p;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Pointer>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
auto
|
|
|
|
to_address(const _Pointer& __p) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return _VSTD::__to_raw_pointer(__p);
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_size_type : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-06-15 05:23:57 +08:00
|
|
|
struct __has_size_type<_Tp,
|
|
|
|
typename __void_t<typename _Tp::size_type>::type> : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-11-18 09:40:00 +08:00
|
|
|
template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __size_type
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-11-18 09:40:00 +08:00
|
|
|
template <class _Alloc, class _DiffType>
|
|
|
|
struct __size_type<_Alloc, _DiffType, true>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_propagate_on_container_copy_assignment : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-06-15 05:23:57 +08:00
|
|
|
struct __has_propagate_on_container_copy_assignment<_Tp,
|
|
|
|
typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
|
|
|
|
: true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
|
|
|
|
struct __propagate_on_container_copy_assignment
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE false_type type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __propagate_on_container_copy_assignment<_Alloc, true>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_propagate_on_container_move_assignment : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_propagate_on_container_move_assignment<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
|
|
|
|
: true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_propagate_on_container_swap : false_type {};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_propagate_on_container_swap<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::propagate_on_container_swap>::type>
|
|
|
|
: true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 05:23:57 +08:00
|
|
|
template <class _Tp, class = void>
|
|
|
|
struct __has_is_always_equal : false_type {};
|
|
|
|
|
2015-06-03 00:34:03 +08:00
|
|
|
template <class _Tp>
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __has_is_always_equal<_Tp,
|
2017-06-15 05:23:57 +08:00
|
|
|
typename __void_t<typename _Tp::is_always_equal>::type>
|
|
|
|
: true_type {};
|
2015-06-03 00:34:03 +08:00
|
|
|
|
|
|
|
template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
|
|
|
|
struct __is_always_equal
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type;
|
2015-06-03 00:34:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __is_always_equal<_Alloc, true>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type;
|
2015-06-03 00:34:03 +08:00
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
|
|
|
|
struct __has_rebind_other
|
|
|
|
{
|
|
|
|
private:
|
2012-10-31 03:06:59 +08:00
|
|
|
struct __two {char __lx; char __lxx;};
|
2010-05-12 03:42:16 +08:00
|
|
|
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
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#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>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
|
|
|
|
struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
|
|
|
|
auto
|
|
|
|
__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
|
2017-09-15 08:31:38 +08:00
|
|
|
-> decltype((void)__a.allocate(__sz, __p), true_type());
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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<
|
2017-09-15 08:31:38 +08:00
|
|
|
decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
|
2010-05-12 03:42:16 +08:00
|
|
|
declval<_SizeType>(),
|
|
|
|
declval<_ConstVoidPtr>())),
|
|
|
|
true_type>::value>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#else // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
|
|
|
|
struct __has_allocate_hint
|
|
|
|
: true_type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#if !defined(_LIBCPP_CXX03_LANG)
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc, class _Tp, class ..._Args>
|
2011-07-01 05:18:19 +08:00
|
|
|
decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
|
|
|
|
_VSTD::declval<_Args>()...),
|
2010-05-12 03:42:16 +08:00
|
|
|
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<
|
2017-09-15 08:31:38 +08:00
|
|
|
decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
|
2010-05-12 03:42:16 +08:00
|
|
|
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<
|
2017-09-15 08:31:38 +08:00
|
|
|
decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
|
2010-05-12 03:42:16 +08:00
|
|
|
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<
|
2017-09-15 08:31:38 +08:00
|
|
|
decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
|
2010-05-12 03:42:16 +08:00
|
|
|
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<
|
2017-09-15 08:31:38 +08:00
|
|
|
decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
|
2010-05-12 03:42:16 +08:00
|
|
|
true_type>::value>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#else // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-12-20 04:08:43 +08:00
|
|
|
template <class _Alloc, class _Pointer, class _Tp, class = void>
|
|
|
|
struct __has_construct : std::false_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-12-20 04:08:43 +08:00
|
|
|
template <class _Alloc, class _Pointer, class _Tp>
|
|
|
|
struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
|
|
|
|
decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
|
|
|
|
>::type> : std::true_type {};
|
2012-02-15 08:41:34 +08:00
|
|
|
|
2018-12-20 04:08:43 +08:00
|
|
|
template <class _Alloc, class _Pointer, class = void>
|
|
|
|
struct __has_destroy : false_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc, class _Pointer>
|
2018-12-20 04:08:43 +08:00
|
|
|
struct __has_destroy<_Alloc, _Pointer, typename __void_t<
|
|
|
|
decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>()))
|
|
|
|
>::type> : std::true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __has_max_size
|
|
|
|
: true_type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __has_select_on_container_copy_construction
|
|
|
|
: false_type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-11-18 09:40:00 +08:00
|
|
|
template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
|
|
|
|
struct __alloc_traits_difference_type
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type;
|
2010-11-18 09:40:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc, class _Ptr>
|
|
|
|
struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type;
|
2010-11-18 09:40:00 +08:00
|
|
|
};
|
|
|
|
|
2019-01-08 08:03:16 +08:00
|
|
|
template <class _Tp>
|
|
|
|
struct __is_default_allocator : false_type {};
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {};
|
|
|
|
|
2019-09-14 00:09:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
template <class _Alloc,
|
|
|
|
bool = __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value && !__is_default_allocator<_Alloc>::value
|
|
|
|
>
|
|
|
|
struct __is_cpp17_move_insertable;
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __is_cpp17_move_insertable<_Alloc, true> : std::true_type {};
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __is_cpp17_move_insertable<_Alloc, false> : std::is_move_constructible<typename _Alloc::value_type> {};
|
|
|
|
|
|
|
|
template <class _Alloc,
|
|
|
|
bool = __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value && !__is_default_allocator<_Alloc>::value
|
|
|
|
>
|
|
|
|
struct __is_cpp17_copy_insertable;
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __is_cpp17_copy_insertable<_Alloc, true> : __is_cpp17_move_insertable<_Alloc> {};
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __is_cpp17_copy_insertable<_Alloc, false> : integral_constant<bool,
|
|
|
|
std::is_copy_constructible<typename _Alloc::value_type>::value &&
|
|
|
|
__is_cpp17_move_insertable<_Alloc>::value>
|
|
|
|
{};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Alloc>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS allocator_traits
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2010-11-18 09:40:00 +08:00
|
|
|
typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
|
|
|
|
typedef typename __size_type<allocator_type, difference_type>::type size_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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;
|
2015-06-03 00:34:03 +08:00
|
|
|
typedef typename __is_always_equal<allocator_type>::type
|
|
|
|
is_always_equal;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp> using rebind_alloc =
|
2011-05-12 04:21:19 +08:00
|
|
|
typename __allocator_traits_rebind<allocator_type, _Tp>::type;
|
2019-06-24 04:47:21 +08:00
|
|
|
template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >;
|
2016-09-25 11:34:28 +08:00
|
|
|
#else // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
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;};
|
2016-09-25 11:34:28 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-11-26 10:55:38 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static pointer allocate(allocator_type& __a, size_type __n)
|
|
|
|
{return __a.allocate(__n);}
|
2017-11-26 10:55:38 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
|
2017-06-01 10:29:37 +08:00
|
|
|
{return __allocate(__a, __n, __hint,
|
2010-05-12 03:42:16 +08:00
|
|
|
__has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{__a.deallocate(__p, __n);}
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
template <class _Tp, class... _Args>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
|
2014-11-12 03:22:33 +08:00
|
|
|
{__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
|
2011-07-01 05:18:19 +08:00
|
|
|
__a, __p, _VSTD::forward<_Args>(__args)...);}
|
2010-08-22 08:02:43 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-01-14 09:33:53 +08:00
|
|
|
static void construct(allocator_type&, _Tp* __p)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
::new ((void*)__p) _Tp();
|
|
|
|
}
|
|
|
|
template <class _Tp, class _A0>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-12-20 04:08:43 +08:00
|
|
|
static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2018-12-20 04:08:43 +08:00
|
|
|
__construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
|
|
|
|
__a, __p, __a0);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
template <class _Tp, class _A0, class _A1>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-01-14 09:33:53 +08:00
|
|
|
static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
|
2010-05-12 03:42:16 +08:00
|
|
|
const _A1& __a1)
|
|
|
|
{
|
|
|
|
::new ((void*)__p) _Tp(__a0, __a1);
|
|
|
|
}
|
|
|
|
template <class _Tp, class _A0, class _A1, class _A2>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-01-14 09:33:53 +08:00
|
|
|
static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
|
2010-05-12 03:42:16 +08:00
|
|
|
const _A1& __a1, const _A2& __a2)
|
|
|
|
{
|
|
|
|
::new ((void*)__p) _Tp(__a0, __a1, __a2);
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static void destroy(allocator_type& __a, _Tp* __p)
|
|
|
|
{__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2013-08-28 04:22:15 +08:00
|
|
|
static size_type max_size(const allocator_type& __a) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __max_size(__has_max_size<const allocator_type>(), __a);}
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static allocator_type
|
|
|
|
select_on_container_copy_construction(const allocator_type& __a)
|
2017-06-01 10:29:37 +08:00
|
|
|
{return __select_on_container_copy_construction(
|
2010-05-12 03:42:16 +08:00
|
|
|
__has_select_on_container_copy_construction<const allocator_type>(),
|
|
|
|
__a);}
|
|
|
|
|
2012-02-15 08:41:34 +08:00
|
|
|
template <class _Ptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static
|
|
|
|
void
|
2019-09-14 00:09:33 +08:00
|
|
|
__construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
|
2012-02-15 08:41:34 +08:00
|
|
|
{
|
2019-09-14 00:09:33 +08:00
|
|
|
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
|
|
|
|
"The specified type does not meet the requirements of Cpp17MoveInsertible");
|
2018-12-08 00:42:28 +08:00
|
|
|
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
|
2019-09-14 00:09:33 +08:00
|
|
|
construct(__a, _VSTD::__to_raw_pointer(__begin2),
|
|
|
|
#ifdef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
_VSTD::move(*__begin1)
|
|
|
|
#else
|
|
|
|
_VSTD::move_if_noexcept(*__begin1)
|
|
|
|
#endif
|
|
|
|
);
|
2012-02-15 08:41:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-01-08 08:03:16 +08:00
|
|
|
(__is_default_allocator<allocator_type>::value
|
2012-02-15 08:41:34 +08:00
|
|
|
|| !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
|
|
|
|
is_trivially_move_constructible<_Tp>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2019-09-14 00:09:33 +08:00
|
|
|
__construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
|
2012-02-15 08:41:34 +08:00
|
|
|
{
|
|
|
|
ptrdiff_t _Np = __end1 - __begin1;
|
2015-05-31 11:13:31 +08:00
|
|
|
if (_Np > 0)
|
2015-06-02 21:04:18 +08:00
|
|
|
{
|
2015-05-31 11:13:31 +08:00
|
|
|
_VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
|
2015-06-02 21:04:18 +08:00
|
|
|
__begin2 += _Np;
|
|
|
|
}
|
2012-02-15 08:41:34 +08:00
|
|
|
}
|
|
|
|
|
[libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.
Summary:
In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++.
This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.
This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`.
This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.
On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`.
Reviewers: howard.hinnant, titus, kcc, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8109
llvm-svn: 233711
2015-04-01 00:54:19 +08:00
|
|
|
template <class _Iter, class _Ptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static
|
|
|
|
void
|
|
|
|
__construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
|
|
|
|
{
|
|
|
|
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
|
|
|
|
construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
|
|
|
|
}
|
|
|
|
|
2019-01-08 08:03:16 +08:00
|
|
|
template <class _SourceTp, class _DestTp,
|
|
|
|
class _RawSourceTp = typename remove_const<_SourceTp>::type,
|
|
|
|
class _RawDestTp = typename remove_const<_DestTp>::type>
|
[libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.
Summary:
In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++.
This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.
This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`.
This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.
On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`.
Reviewers: howard.hinnant, titus, kcc, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8109
llvm-svn: 233711
2015-04-01 00:54:19 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-01-08 08:03:16 +08:00
|
|
|
is_trivially_move_constructible<_DestTp>::value &&
|
|
|
|
is_same<_RawSourceTp, _RawDestTp>::value &&
|
|
|
|
(__is_default_allocator<allocator_type>::value ||
|
|
|
|
!__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
|
[libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.
Summary:
In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++.
This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.
This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`.
This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.
On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`.
Reviewers: howard.hinnant, titus, kcc, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8109
llvm-svn: 233711
2015-04-01 00:54:19 +08:00
|
|
|
void
|
|
|
|
>::type
|
2019-01-08 08:03:16 +08:00
|
|
|
__construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
|
[libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.
Summary:
In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++.
This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.
This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`.
This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.
On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`.
Reviewers: howard.hinnant, titus, kcc, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8109
llvm-svn: 233711
2015-04-01 00:54:19 +08:00
|
|
|
{
|
|
|
|
ptrdiff_t _Np = __end1 - __begin1;
|
2015-05-31 11:13:31 +08:00
|
|
|
if (_Np > 0)
|
2015-06-02 21:04:18 +08:00
|
|
|
{
|
2019-01-08 08:03:16 +08:00
|
|
|
_VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
|
2015-06-02 21:04:18 +08:00
|
|
|
__begin2 += _Np;
|
|
|
|
}
|
[libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.
Summary:
In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++.
This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.
This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`.
This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.
On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`.
Reviewers: howard.hinnant, titus, kcc, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8109
llvm-svn: 233711
2015-04-01 00:54:19 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 08:41:34 +08:00
|
|
|
template <class _Ptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static
|
|
|
|
void
|
2019-09-14 00:09:33 +08:00
|
|
|
__construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
|
2012-02-15 08:41:34 +08:00
|
|
|
{
|
2019-09-14 00:09:33 +08:00
|
|
|
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
|
|
|
|
"The specified type does not meet the requirements of Cpp17MoveInsertable");
|
2012-02-15 08:41:34 +08:00
|
|
|
while (__end1 != __begin1)
|
2013-01-12 04:36:59 +08:00
|
|
|
{
|
2019-09-14 00:09:33 +08:00
|
|
|
construct(__a, _VSTD::__to_raw_pointer(__end2 - 1),
|
|
|
|
#ifdef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
_VSTD::move(*--__end1)
|
|
|
|
#else
|
|
|
|
_VSTD::move_if_noexcept(*--__end1)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
--__end2;
|
2013-01-12 04:36:59 +08:00
|
|
|
}
|
2012-02-15 08:41:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-01-08 08:03:16 +08:00
|
|
|
(__is_default_allocator<allocator_type>::value
|
2012-02-15 08:41:34 +08:00
|
|
|
|| !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
|
|
|
|
is_trivially_move_constructible<_Tp>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2019-09-14 00:09:33 +08:00
|
|
|
__construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
|
2012-02-15 08:41:34 +08:00
|
|
|
{
|
|
|
|
ptrdiff_t _Np = __end1 - __begin1;
|
|
|
|
__end2 -= _Np;
|
2015-05-31 11:13:31 +08:00
|
|
|
if (_Np > 0)
|
|
|
|
_VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
|
2012-02-15 08:41:34 +08:00
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-06-01 10:29:37 +08:00
|
|
|
static pointer __allocate(allocator_type& __a, size_type __n,
|
2010-05-12 03:42:16 +08:00
|
|
|
const_void_pointer __hint, true_type)
|
|
|
|
{return __a.allocate(__n, __hint);}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-06-01 10:29:37 +08:00
|
|
|
static pointer __allocate(allocator_type& __a, size_type __n,
|
2011-12-02 04:21:04 +08:00
|
|
|
const_void_pointer, false_type)
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __a.allocate(__n);}
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
template <class _Tp, class... _Args>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
|
2011-07-01 05:18:19 +08:00
|
|
|
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class... _Args>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
2018-12-20 04:08:43 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
template <class _Tp, class _A0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static void __construct(true_type, allocator_type& __a, _Tp* __p,
|
|
|
|
const _A0& __a0)
|
|
|
|
{__a.construct(__p, __a0);}
|
|
|
|
template <class _Tp, class _A0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static void __construct(false_type, allocator_type&, _Tp* __p,
|
|
|
|
const _A0& __a0)
|
|
|
|
{
|
|
|
|
::new ((void*)__p) _Tp(__a0);
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static void __destroy(true_type, allocator_type& __a, _Tp* __p)
|
|
|
|
{__a.destroy(__p);}
|
|
|
|
template <class _Tp>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static void __destroy(false_type, allocator_type&, _Tp* __p)
|
|
|
|
{
|
|
|
|
__p->~_Tp();
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-12-05 23:56:26 +08:00
|
|
|
static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __a.max_size();}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-12-05 23:56:26 +08:00
|
|
|
static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
|
2015-10-26 03:34:04 +08:00
|
|
|
{return numeric_limits<size_type>::max() / sizeof(value_type);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static allocator_type
|
2017-06-01 10:29:37 +08:00
|
|
|
__select_on_container_copy_construction(true_type, const allocator_type& __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __a.select_on_container_copy_construction();}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
static allocator_type
|
2017-06-01 10:29:37 +08:00
|
|
|
__select_on_container_copy_construction(false_type, const allocator_type& __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __a;}
|
|
|
|
};
|
|
|
|
|
2015-04-07 13:21:38 +08:00
|
|
|
template <class _Traits, class _Tp>
|
|
|
|
struct __rebind_alloc_helper
|
|
|
|
{
|
2016-09-25 11:34:28 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type;
|
2015-04-07 13:21:38 +08:00
|
|
|
#else
|
|
|
|
typedef typename _Traits::template rebind_alloc<_Tp>::other type;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// allocator
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS allocator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2011-06-03 05:38:57 +08:00
|
|
|
typedef true_type propagate_on_container_move_assignment;
|
2015-06-03 00:34:03 +08:00
|
|
|
typedef true_type is_always_equal;
|
2011-06-03 05:38:57 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Up> struct rebind {typedef allocator<_Up> other;};
|
|
|
|
|
2018-03-21 07:02:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
allocator() _NOEXCEPT {}
|
|
|
|
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
template <class _Up>
|
2018-03-21 07:02:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
allocator(const allocator<_Up>&) _NOEXCEPT {}
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
{return _VSTD::addressof(__x);}
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
{return _VSTD::addressof(__x);}
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2017-11-26 10:55:38 +08:00
|
|
|
pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
|
2016-03-03 20:04:39 +08:00
|
|
|
{
|
|
|
|
if (__n > max_size())
|
2016-08-26 01:47:09 +08:00
|
|
|
__throw_length_error("allocator<T>::allocate(size_t n)"
|
|
|
|
" 'n' exceeds maximum supported size");
|
2019-01-16 09:51:12 +08:00
|
|
|
return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
|
2016-03-03 20:04:39 +08:00
|
|
|
}
|
2018-10-26 01:21:30 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
|
2019-01-16 09:51:12 +08:00
|
|
|
{_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
|
|
|
{return size_type(~0) / sizeof(_Tp);}
|
2010-09-05 07:28:19 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Up, class... _Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(_Up* __p, _Args&&... __args)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
2010-09-05 07:28:19 +08:00
|
|
|
#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(pointer __p)
|
|
|
|
{
|
|
|
|
::new((void*)__p) _Tp();
|
|
|
|
}
|
2010-12-11 03:47:54 +08:00
|
|
|
# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
|
2012-05-01 23:37:54 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _A0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-05-01 23:37:54 +08:00
|
|
|
void
|
2010-05-12 03:42:16 +08:00
|
|
|
construct(pointer __p, _A0& __a0)
|
|
|
|
{
|
|
|
|
::new((void*)__p) _Tp(__a0);
|
|
|
|
}
|
|
|
|
template <class _A0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-05-01 23:37:54 +08:00
|
|
|
void
|
2010-05-12 03:42:16 +08:00
|
|
|
construct(pointer __p, const _A0& __a0)
|
|
|
|
{
|
|
|
|
::new((void*)__p) _Tp(__a0);
|
|
|
|
}
|
2010-12-11 03:47:54 +08:00
|
|
|
# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
|
2010-05-12 03:42:16 +08:00
|
|
|
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);
|
|
|
|
}
|
2010-09-05 07:28:19 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
|
|
|
|
};
|
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
template <class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
|
2012-01-03 01:56:02 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef const _Tp* pointer;
|
|
|
|
typedef const _Tp* const_pointer;
|
|
|
|
typedef const _Tp& reference;
|
|
|
|
typedef const _Tp& const_reference;
|
2013-06-07 09:56:37 +08:00
|
|
|
typedef const _Tp value_type;
|
2012-01-03 01:56:02 +08:00
|
|
|
|
|
|
|
typedef true_type propagate_on_container_move_assignment;
|
2015-07-02 05:23:40 +08:00
|
|
|
typedef true_type is_always_equal;
|
2012-01-03 01:56:02 +08:00
|
|
|
|
|
|
|
template <class _Up> struct rebind {typedef allocator<_Up> other;};
|
|
|
|
|
2018-03-21 07:02:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
|
|
allocator() _NOEXCEPT {}
|
|
|
|
|
|
|
|
template <class _Up>
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
2018-03-21 07:02:53 +08:00
|
|
|
allocator(const allocator<_Up>&) _NOEXCEPT {}
|
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
|
|
|
|
{return _VSTD::addressof(__x);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
|
2016-03-03 20:04:39 +08:00
|
|
|
{
|
|
|
|
if (__n > max_size())
|
2016-08-26 01:47:09 +08:00
|
|
|
__throw_length_error("allocator<const T>::allocate(size_t n)"
|
|
|
|
" 'n' exceeds maximum supported size");
|
2019-01-16 09:51:12 +08:00
|
|
|
return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
|
2016-05-07 11:12:24 +08:00
|
|
|
}
|
2018-10-26 01:21:30 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
|
2019-01-16 09:51:12 +08:00
|
|
|
{_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
|
2012-01-03 01:56:02 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
|
|
|
{return size_type(~0) / sizeof(_Tp);}
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
|
|
|
template <class _Up, class... _Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(_Up* __p, _Args&&... __args)
|
|
|
|
{
|
|
|
|
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
|
|
|
|
}
|
|
|
|
#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(pointer __p)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp();
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
|
2012-05-01 23:37:54 +08:00
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
template <class _A0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-05-01 23:37:54 +08:00
|
|
|
void
|
2012-01-03 01:56:02 +08:00
|
|
|
construct(pointer __p, _A0& __a0)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
template <class _A0>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-05-01 23:37:54 +08:00
|
|
|
void
|
2012-01-03 01:56:02 +08:00
|
|
|
construct(pointer __p, const _A0& __a0)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
|
|
|
|
template <class _A0, class _A1>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(pointer __p, _A0& __a0, _A1& __a1)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
template <class _A0, class _A1>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(pointer __p, const _A0& __a0, _A1& __a1)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
template <class _A0, class _A1>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(pointer __p, _A0& __a0, const _A1& __a1)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
template <class _A0, class _A1>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
construct(pointer __p, const _A0& __a0, const _A1& __a1)
|
|
|
|
{
|
2017-06-15 00:54:43 +08:00
|
|
|
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
2012-01-03 01:56:02 +08:00
|
|
|
}
|
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _OutputIterator, class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
: 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)
|
2018-08-28 21:29:30 +08:00
|
|
|
{::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
|
2015-10-26 02:58:07 +08:00
|
|
|
#if _LIBCPP_STD_VER >= 14
|
|
|
|
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
|
2018-08-28 21:29:30 +08:00
|
|
|
{::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
|
2015-10-26 02:58:07 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
_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;}
|
2015-05-10 21:14:08 +08:00
|
|
|
#if _LIBCPP_STD_VER >= 14
|
2017-08-20 18:38:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
|
2015-05-10 21:14:08 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
[libc++] Add _LIBCPP_ENABLE_NODISCARD and _LIBCPP_NODISCARD_EXT to allow pre-C++2a [[nodiscard]]
Summary:
The `[[nodiscard]]` attribute is intended to help users find bugs where
function return values are ignored when they shouldn't be. After C++17 the
C++ standard has started to declared such library functions as `[[nodiscard]]`.
However, this application is limited and applies only to dialects after C++17.
Users who want help diagnosing misuses of STL functions may desire a more
liberal application of `[[nodiscard]]`.
For this reason libc++ provides an extension that does just that! The
extension must be enabled by defining `_LIBCPP_ENABLE_NODISCARD`. The extended
applications of `[[nodiscard]]` takes two forms:
1. Backporting `[[nodiscard]]` to entities declared as such by the
standard in newer dialects, but not in the present one.
2. Extended applications of `[[nodiscard]]`, at the libraries discretion,
applied to entities never declared as such by the standard.
Users may also opt-out of additional applications `[[nodiscard]]` using
additional macros.
Applications of the first form, which backport `[[nodiscard]]` from a newer
dialect may be disabled using macros specific to the dialect it was added. For
example `_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17`.
Applications of the second form, which are pure extensions, may be disabled
by defining `_LIBCPP_DISABLE_NODISCARD_EXT`.
This patch was originally written by me (Roman Lebedev),
then but then reworked by Eric Fiselier.
Reviewers: mclow.lists, thakis, EricWF
Reviewed By: thakis, EricWF
Subscribers: llvm-commits, mclow.lists, lebedev.ri, EricWF, rjmccall, Quuxplusone, cfe-commits, christof
Differential Revision: https://reviews.llvm.org/D45179
llvm-svn: 342808
2018-09-23 01:54:48 +08:00
|
|
|
_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
|
2010-05-12 03:42:16 +08:00
|
|
|
pair<_Tp*, ptrdiff_t>
|
2011-05-28 22:41:13 +08:00
|
|
|
get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2018-10-27 01:12:32 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
|
2019-01-16 09:51:12 +08:00
|
|
|
if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
|
2018-02-02 06:24:45 +08:00
|
|
|
{
|
|
|
|
std::align_val_t __al =
|
|
|
|
std::align_val_t(std::alignment_of<_Tp>::value);
|
|
|
|
__r.first = static_cast<_Tp*>(::operator new(
|
|
|
|
__n * sizeof(_Tp), __al, nothrow));
|
|
|
|
} else {
|
|
|
|
__r.first = static_cast<_Tp*>(::operator new(
|
|
|
|
__n * sizeof(_Tp), nothrow));
|
|
|
|
}
|
|
|
|
#else
|
2019-01-16 09:51:12 +08:00
|
|
|
if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
|
2018-02-02 06:24:45 +08:00
|
|
|
{
|
|
|
|
// Since aligned operator new is unavailable, return an empty
|
|
|
|
// buffer rather than one with invalid alignment.
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
__r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
|
2018-02-02 06:24:45 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__r.first)
|
|
|
|
{
|
|
|
|
__r.second = __n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__n /= 2;
|
|
|
|
}
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-02-02 06:24:45 +08:00
|
|
|
void return_temporary_buffer(_Tp* __p) _NOEXCEPT
|
|
|
|
{
|
2019-01-16 09:51:12 +08:00
|
|
|
_VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
|
2018-02-02 06:24:45 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
_Tp* __ptr_;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class _Tp>
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
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 <>
|
[libc++] Add deprecated attributes to many deprecated components
Summary:
These deprecation warnings are opt-in: they are only enabled when the
_LIBCXX_DEPRECATION_WARNINGS macro is defined, which is not the case
by default. Note that this is a first step in the right direction, but
I wasn't able to get an exhaustive list of all deprecated components
per standard, so there's certainly stuff that's missing. The list of
components this commit marks as deprecated is:
in C++11:
- auto_ptr, auto_ptr_ref
- binder1st, binder2nd, bind1st(), bind2nd()
- pointer_to_unary_function, pointer_to_binary_function, ptr_fun()
- mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t, mem_fun()
- mem_fun_ref_t, mem_fun1_ref_t, const_mem_fun_ref_t, const_mem_fun1_ref_t, mem_fun_ref()
in C++14:
- random_shuffle()
in C++17:
- unary_negate, binary_negate, not1(), not2()
<rdar://problem/18168350>
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D48912
llvm-svn: 342843
2018-09-24 02:35:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void element_type;
|
|
|
|
};
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
template <class _Tp, int _Idx,
|
|
|
|
bool _CanBeEmptyBase =
|
|
|
|
is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
|
|
|
|
struct __compressed_pair_elem {
|
|
|
|
typedef _Tp _ParamT;
|
|
|
|
typedef _Tp& reference;
|
|
|
|
typedef const _Tp& const_reference;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
|
2017-04-13 07:45:53 +08:00
|
|
|
|
|
|
|
template <class _Up, class = typename enable_if<
|
2017-04-18 06:32:02 +08:00
|
|
|
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
|
|
|
|
>::type>
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-18 06:32:02 +08:00
|
|
|
constexpr explicit
|
2017-04-13 07:45:53 +08:00
|
|
|
__compressed_pair_elem(_Up&& __u)
|
2018-10-01 09:59:37 +08:00
|
|
|
: __value_(_VSTD::forward<_Up>(__u))
|
|
|
|
{
|
|
|
|
}
|
2017-04-13 07:45:53 +08:00
|
|
|
|
|
|
|
template <class... _Args, size_t... _Indexes>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
|
|
|
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
|
|
|
|
__tuple_indices<_Indexes...>)
|
|
|
|
: __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
|
|
|
|
#else
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-13 07:45:53 +08:00
|
|
|
__compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-13 07:45:53 +08:00
|
|
|
const_reference __get() const _NOEXCEPT { return __value_; }
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
2017-04-13 07:45:53 +08:00
|
|
|
_Tp __value_;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
template <class _Tp, int _Idx>
|
|
|
|
struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
|
|
|
|
typedef _Tp _ParamT;
|
|
|
|
typedef _Tp& reference;
|
|
|
|
typedef const _Tp& const_reference;
|
|
|
|
typedef _Tp __value_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
|
2017-04-13 07:45:53 +08:00
|
|
|
|
|
|
|
template <class _Up, class = typename enable_if<
|
2017-04-18 06:32:02 +08:00
|
|
|
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
|
|
|
|
>::type>
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-18 06:32:02 +08:00
|
|
|
constexpr explicit
|
2017-04-13 07:45:53 +08:00
|
|
|
__compressed_pair_elem(_Up&& __u)
|
2018-10-01 09:59:37 +08:00
|
|
|
: __value_type(_VSTD::forward<_Up>(__u))
|
|
|
|
{}
|
2017-04-13 07:45:53 +08:00
|
|
|
|
|
|
|
template <class... _Args, size_t... _Indexes>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
|
|
|
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
|
|
|
|
__tuple_indices<_Indexes...>)
|
|
|
|
: __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
|
|
|
|
#else
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-13 07:45:53 +08:00
|
|
|
__compressed_pair_elem(_ParamT __p)
|
|
|
|
: __value_type(std::forward<_ParamT>(__p)) {}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-11-10 01:54:49 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-13 07:45:53 +08:00
|
|
|
const_reference __get() const _NOEXCEPT { return *this; }
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
// Tag used to construct the second element of the compressed pair.
|
|
|
|
struct __second_tag {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _T1, class _T2>
|
2017-04-13 07:45:53 +08:00
|
|
|
class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
|
|
|
|
private __compressed_pair_elem<_T2, 1> {
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
|
|
|
|
typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
|
2017-04-13 07:45:53 +08:00
|
|
|
|
|
|
|
// NOTE: This static assert should never fire because __compressed_pair
|
|
|
|
// is *almost never* used in a scenario where it's possible for T1 == T2.
|
|
|
|
// (The exception is std::function where it is possible that the function
|
|
|
|
// object and the allocator have the same type).
|
2017-04-13 09:13:58 +08:00
|
|
|
static_assert((!is_same<_T1, _T2>::value),
|
2017-04-13 07:45:53 +08:00
|
|
|
"__compressed_pair cannot be instantated when T1 and T2 are the same type; "
|
|
|
|
"The current implementation is NOT ABI-compatible with the previous "
|
|
|
|
"implementation for this configuration");
|
2011-12-20 01:58:44 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2017-04-13 07:45:53 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2017-04-18 06:32:02 +08:00
|
|
|
template <bool _Dummy = true,
|
|
|
|
class = typename enable_if<
|
|
|
|
__dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
|
|
|
|
__dependent_type<is_default_constructible<_T2>, _Dummy>::value
|
|
|
|
>::type
|
|
|
|
>
|
2017-04-13 07:45:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-18 06:32:02 +08:00
|
|
|
constexpr __compressed_pair() {}
|
2017-04-13 07:45:53 +08:00
|
|
|
|
|
|
|
template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
|
|
|
|
__compressed_pair>::value,
|
|
|
|
bool>::type = true>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr explicit
|
|
|
|
__compressed_pair(_Tp&& __t)
|
|
|
|
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
|
|
|
__compressed_pair(__second_tag, _Tp&& __t)
|
|
|
|
: _Base1(), _Base2(std::forward<_Tp>(__t)) {}
|
|
|
|
|
|
|
|
template <class _U1, class _U2>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr
|
|
|
|
__compressed_pair(_U1&& __t1, _U2&& __t2)
|
|
|
|
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
|
|
|
|
|
|
|
|
template <class... _Args1, class... _Args2>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
|
|
|
__compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
|
|
|
|
tuple<_Args2...> __second_args)
|
|
|
|
: _Base1(__pc, _VSTD::move(__first_args),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Args1)>::type()),
|
|
|
|
_Base2(__pc, _VSTD::move(__second_args),
|
|
|
|
typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
#else
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__compressed_pair() {}
|
2011-12-20 01:58:44 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY explicit
|
|
|
|
__compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
|
2011-12-20 01:58:44 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__compressed_pair(__second_tag, _T2 __t2)
|
|
|
|
: _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
|
2011-12-20 01:58:44 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__compressed_pair(_T1 __t1, _T2 __t2)
|
|
|
|
: _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-13 07:45:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename _Base1::reference first() _NOEXCEPT {
|
|
|
|
return static_cast<_Base1&>(*this).__get();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename _Base1::const_reference first() const _NOEXCEPT {
|
|
|
|
return static_cast<_Base1 const&>(*this).__get();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename _Base2::reference second() _NOEXCEPT {
|
|
|
|
return static_cast<_Base2&>(*this).__get();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename _Base2::const_reference second() const _NOEXCEPT {
|
|
|
|
return static_cast<_Base2 const&>(*this).__get();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void swap(__compressed_pair& __x)
|
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
|
|
|
|
__is_nothrow_swappable<_T2>::value)
|
|
|
|
{
|
|
|
|
using std::swap;
|
|
|
|
swap(first(), __x.first());
|
|
|
|
swap(second(), __x.second());
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _T1, class _T2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-04-13 07:45:53 +08:00
|
|
|
void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
|
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
|
|
|
|
__is_nothrow_swappable<_T2>::value) {
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
// default_delete
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp>
|
2017-04-16 10:06:25 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS default_delete {
|
2017-05-25 23:43:31 +08:00
|
|
|
static_assert(!is_function<_Tp>::value,
|
|
|
|
"default_delete cannot be instantiated for function types");
|
2017-04-16 10:06:25 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-24 04:47:21 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
|
2012-07-08 04:56:04 +08:00
|
|
|
#else
|
2017-04-16 10:06:25 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY default_delete() {}
|
2012-07-08 04:56:04 +08:00
|
|
|
#endif
|
2017-04-16 10:06:25 +08:00
|
|
|
template <class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
default_delete(const default_delete<_Up>&,
|
|
|
|
typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
|
|
|
|
0) _NOEXCEPT {}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
|
|
|
|
static_assert(sizeof(_Tp) > 0,
|
|
|
|
"default_delete can not delete incomplete type");
|
|
|
|
static_assert(!is_void<_Tp>::value,
|
|
|
|
"default_delete can not delete incomplete type");
|
|
|
|
delete __ptr;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-04-16 10:06:25 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
|
|
|
|
private:
|
|
|
|
template <class _Up>
|
|
|
|
struct _EnableIfConvertible
|
|
|
|
: enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
|
|
|
|
|
2011-12-19 05:19:44 +08:00
|
|
|
public:
|
2017-04-16 10:06:25 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2019-06-24 04:47:21 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
|
2012-07-08 04:56:04 +08:00
|
|
|
#else
|
2017-04-16 10:06:25 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY default_delete() {}
|
2012-07-08 04:56:04 +08:00
|
|
|
#endif
|
2017-04-16 10:06:25 +08:00
|
|
|
|
|
|
|
template <class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
default_delete(const default_delete<_Up[]>&,
|
|
|
|
typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
|
|
|
|
|
|
|
|
template <class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename _EnableIfConvertible<_Up>::type
|
|
|
|
operator()(_Up* __ptr) const _NOEXCEPT {
|
|
|
|
static_assert(sizeof(_Tp) > 0,
|
|
|
|
"default_delete can not delete incomplete type");
|
|
|
|
static_assert(!is_void<_Tp>::value,
|
|
|
|
"default_delete can not delete void type");
|
|
|
|
delete[] __ptr;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Deleter>
|
|
|
|
struct __unique_ptr_deleter_sfinae {
|
|
|
|
static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
|
|
|
|
typedef const _Deleter& __lval_ref_type;
|
|
|
|
typedef _Deleter&& __good_rval_ref_type;
|
|
|
|
typedef true_type __enable_rval_overload;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Deleter>
|
|
|
|
struct __unique_ptr_deleter_sfinae<_Deleter const&> {
|
|
|
|
typedef const _Deleter& __lval_ref_type;
|
|
|
|
typedef const _Deleter&& __bad_rval_ref_type;
|
|
|
|
typedef false_type __enable_rval_overload;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Deleter>
|
|
|
|
struct __unique_ptr_deleter_sfinae<_Deleter&> {
|
|
|
|
typedef _Deleter& __lval_ref_type;
|
|
|
|
typedef _Deleter&& __bad_rval_ref_type;
|
|
|
|
typedef false_type __enable_rval_overload;
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Dp = default_delete<_Tp> >
|
2017-04-16 09:51:04 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS unique_ptr {
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2017-04-16 09:51:04 +08:00
|
|
|
typedef _Tp element_type;
|
|
|
|
typedef _Dp deleter_type;
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
static_assert(!is_rvalue_reference<deleter_type>::value,
|
|
|
|
"the specified deleter type cannot be an rvalue reference");
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
2017-04-16 09:51:04 +08:00
|
|
|
__compressed_pair<pointer, deleter_type> __ptr_;
|
|
|
|
|
|
|
|
struct __nat { int __for_bool_; };
|
|
|
|
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _LValRefType _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 10:14:31 +08:00
|
|
|
typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 10:14:31 +08:00
|
|
|
typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 10:14:31 +08:00
|
|
|
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy, class _Deleter = typename __dependent_type<
|
|
|
|
__identity<deleter_type>, _Dummy>::type>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 09:51:04 +08:00
|
|
|
typename enable_if<is_default_constructible<_Deleter>::value &&
|
|
|
|
!is_pointer<_Deleter>::value>::type;
|
|
|
|
|
|
|
|
template <class _ArgType>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 09:51:04 +08:00
|
|
|
typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
|
|
|
|
|
|
|
|
template <class _UPtr, class _Up>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
|
2017-04-16 09:51:04 +08:00
|
|
|
is_convertible<typename _UPtr::pointer, pointer>::value &&
|
|
|
|
!is_array<_Up>::value
|
|
|
|
>::type;
|
|
|
|
|
|
|
|
template <class _UDel>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
|
2017-04-16 09:51:04 +08:00
|
|
|
(is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
|
|
|
|
(!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
|
|
|
|
>::type;
|
|
|
|
|
|
|
|
template <class _UDel>
|
|
|
|
using _EnableIfDeleterAssignable = typename enable_if<
|
|
|
|
is_assignable<_Dp&, _UDel&&>::value
|
|
|
|
>::type;
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2017-04-16 09:51:04 +08:00
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
_LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
_LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p) {}
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__p, __d) {}
|
|
|
|
|
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__p, _VSTD::move(__d)) {
|
|
|
|
static_assert(!is_reference<deleter_type>::value,
|
|
|
|
"rvalue deleter bound to reference");
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(unique_ptr&& __u) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Up, class _Ep,
|
|
|
|
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
|
|
|
|
class = _EnableIfDeleterConvertible<_Ep>
|
|
|
|
>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
|
|
|
|
: __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr(auto_ptr<_Up>&& __p,
|
|
|
|
typename enable_if<is_convertible<_Up*, _Tp*>::value &&
|
2019-06-24 04:47:21 +08:00
|
|
|
is_same<_Dp, default_delete<_Tp> >::value,
|
2017-04-16 09:51:04 +08:00
|
|
|
__nat>::type = __nat()) _NOEXCEPT
|
|
|
|
: __ptr_(__p.release()) {}
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
|
|
|
|
reset(__u.release());
|
|
|
|
__ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
|
|
|
|
return *this;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Up, class _Ep,
|
|
|
|
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
|
|
|
|
class = _EnableIfDeleterAssignable<_Ep>
|
|
|
|
>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
|
|
|
|
reset(__u.release());
|
|
|
|
__ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
|
|
|
|
return *this;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2017-04-16 09:51:04 +08:00
|
|
|
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;
|
|
|
|
}
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2019-06-24 04:47:21 +08:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
|
|
|
unique_ptr(unique_ptr const&) = delete;
|
|
|
|
unique_ptr& operator=(unique_ptr const&) = delete;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
~unique_ptr() { reset(); }
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr& operator=(nullptr_t) _NOEXCEPT {
|
|
|
|
reset();
|
|
|
|
return *this;
|
|
|
|
}
|
2011-05-28 22:41:13 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename add_lvalue_reference<_Tp>::type
|
|
|
|
operator*() const {
|
|
|
|
return *__ptr_.first();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pointer operator->() const _NOEXCEPT {
|
|
|
|
return __ptr_.first();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pointer get() const _NOEXCEPT {
|
|
|
|
return __ptr_.first();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
deleter_type& get_deleter() _NOEXCEPT {
|
|
|
|
return __ptr_.second();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const deleter_type& get_deleter() const _NOEXCEPT {
|
|
|
|
return __ptr_.second();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
|
|
|
|
return __ptr_.first() != nullptr;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pointer release() _NOEXCEPT {
|
|
|
|
pointer __t = __ptr_.first();
|
|
|
|
__ptr_.first() = pointer();
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void reset(pointer __p = pointer()) _NOEXCEPT {
|
|
|
|
pointer __tmp = __ptr_.first();
|
|
|
|
__ptr_.first() = __p;
|
|
|
|
if (__tmp)
|
|
|
|
__ptr_.second()(__tmp);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void swap(unique_ptr& __u) _NOEXCEPT {
|
|
|
|
__ptr_.swap(__u.__ptr_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Dp>
|
2017-04-16 09:51:04 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2017-04-16 09:51:04 +08:00
|
|
|
typedef _Tp element_type;
|
|
|
|
typedef _Dp deleter_type;
|
|
|
|
typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
2017-04-16 09:51:04 +08:00
|
|
|
__compressed_pair<pointer, deleter_type> __ptr_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 10:14:31 +08:00
|
|
|
template <class _From>
|
|
|
|
struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 10:14:31 +08:00
|
|
|
template <class _FromElem>
|
|
|
|
struct _CheckArrayPointerConversion<_FromElem*>
|
|
|
|
: integral_constant<bool,
|
|
|
|
is_same<_FromElem*, pointer>::value ||
|
|
|
|
(is_same<pointer, element_type*>::value &&
|
|
|
|
is_convertible<_FromElem(*)[], element_type(*)[]>::value)
|
|
|
|
>
|
|
|
|
{};
|
2017-04-16 09:51:04 +08:00
|
|
|
|
2017-04-16 10:14:31 +08:00
|
|
|
typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _LValRefType _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 10:14:31 +08:00
|
|
|
typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 10:14:31 +08:00
|
|
|
typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 10:14:31 +08:00
|
|
|
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
template <bool _Dummy, class _Deleter = typename __dependent_type<
|
|
|
|
__identity<deleter_type>, _Dummy>::type>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 09:51:04 +08:00
|
|
|
typename enable_if<is_default_constructible<_Deleter>::value &&
|
|
|
|
!is_pointer<_Deleter>::value>::type;
|
|
|
|
|
|
|
|
template <class _ArgType>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
|
2017-04-16 09:51:04 +08:00
|
|
|
typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
|
|
|
|
|
|
|
|
template <class _Pp>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
|
2017-04-16 10:14:31 +08:00
|
|
|
_CheckArrayPointerConversion<_Pp>::value
|
2017-04-16 09:51:04 +08:00
|
|
|
>::type;
|
|
|
|
|
|
|
|
template <class _UPtr, class _Up,
|
|
|
|
class _ElemT = typename _UPtr::element_type>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
|
2017-04-16 09:51:04 +08:00
|
|
|
is_array<_Up>::value &&
|
|
|
|
is_same<pointer, element_type*>::value &&
|
|
|
|
is_same<typename _UPtr::pointer, _ElemT*>::value &&
|
|
|
|
is_convertible<_ElemT(*)[], element_type(*)[]>::value
|
|
|
|
>::type;
|
|
|
|
|
|
|
|
template <class _UDel>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
|
2017-04-16 09:51:04 +08:00
|
|
|
(is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
|
|
|
|
(!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
|
|
|
|
>::type;
|
|
|
|
|
|
|
|
template <class _UDel>
|
2019-06-12 10:03:31 +08:00
|
|
|
using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if<
|
2017-04-16 09:51:04 +08:00
|
|
|
is_assignable<_Dp&, _UDel&&>::value
|
|
|
|
>::type;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
public:
|
2017-04-16 09:51:04 +08:00
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
_LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
_LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Pp, bool _Dummy = true,
|
|
|
|
class = _EnableIfDeleterDefaultConstructible<_Dummy>,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfPointerConvertible<_Pp> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
explicit unique_ptr(_Pp __p) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__p) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Pp, bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
|
|
|
|
class = _EnableIfPointerConvertible<_Pp> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__p, __d) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(nullptr, __d) {}
|
2011-12-19 05:19:44 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Pp, bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
|
|
|
|
class = _EnableIfPointerConvertible<_Pp> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__p, _VSTD::move(__d)) {
|
|
|
|
static_assert(!is_reference<deleter_type>::value,
|
|
|
|
"rvalue deleter bound to reference");
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(nullptr, _VSTD::move(__d)) {
|
|
|
|
static_assert(!is_reference<deleter_type>::value,
|
|
|
|
"rvalue deleter bound to reference");
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Pp, bool _Dummy = true,
|
2019-06-24 04:47:21 +08:00
|
|
|
class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
|
|
|
|
class = _EnableIfPointerConvertible<_Pp> >
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(unique_ptr&& __u) _NOEXCEPT
|
2017-04-16 09:51:04 +08:00
|
|
|
: __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
|
2017-04-16 09:51:04 +08:00
|
|
|
reset(__u.release());
|
|
|
|
__ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
|
|
|
|
return *this;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Up, class _Ep,
|
|
|
|
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
|
|
|
|
class = _EnableIfDeleterConvertible<_Ep>
|
|
|
|
>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
|
2017-04-18 04:20:27 +08:00
|
|
|
: __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
|
2017-04-16 09:51:04 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 09:51:04 +08:00
|
|
|
template <class _Up, class _Ep,
|
|
|
|
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
|
|
|
|
class = _EnableIfDeleterAssignable<_Ep>
|
|
|
|
>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr&
|
2019-06-24 04:47:21 +08:00
|
|
|
operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
|
2017-04-16 09:51:04 +08:00
|
|
|
reset(__u.release());
|
|
|
|
__ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
|
|
|
|
return *this;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2019-06-24 04:47:21 +08:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
|
|
|
unique_ptr(unique_ptr const&) = delete;
|
|
|
|
unique_ptr& operator=(unique_ptr const&) = delete;
|
|
|
|
#endif
|
2017-04-16 09:51:04 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
~unique_ptr() { reset(); }
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
unique_ptr& operator=(nullptr_t) _NOEXCEPT {
|
|
|
|
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 _NOEXCEPT {
|
|
|
|
return __ptr_.first();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
deleter_type& get_deleter() _NOEXCEPT {
|
|
|
|
return __ptr_.second();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const deleter_type& get_deleter() const _NOEXCEPT {
|
|
|
|
return __ptr_.second();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
|
|
|
|
return __ptr_.first() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pointer release() _NOEXCEPT {
|
|
|
|
pointer __t = __ptr_.first();
|
|
|
|
__ptr_.first() = pointer();
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Pp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename enable_if<
|
2017-04-16 10:14:31 +08:00
|
|
|
_CheckArrayPointerConversion<_Pp>::value
|
2017-04-16 09:51:04 +08:00
|
|
|
>::type
|
|
|
|
reset(_Pp __p) _NOEXCEPT {
|
|
|
|
pointer __tmp = __ptr_.first();
|
|
|
|
__ptr_.first() = __p;
|
|
|
|
if (__tmp)
|
|
|
|
__ptr_.second()(__tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void reset(nullptr_t = nullptr) _NOEXCEPT {
|
|
|
|
pointer __tmp = __ptr_.first();
|
|
|
|
__ptr_.first() = nullptr;
|
|
|
|
if (__tmp)
|
|
|
|
__ptr_.second()(__tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void swap(unique_ptr& __u) _NOEXCEPT {
|
|
|
|
__ptr_.swap(__u.__ptr_);
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Dp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-04-22 07:38:59 +08:00
|
|
|
typename enable_if<
|
|
|
|
__is_swappable<_Dp>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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
|
2012-02-22 05:02:58 +08:00
|
|
|
operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
|
|
|
|
{
|
|
|
|
typedef typename unique_ptr<_T1, _D1>::pointer _P1;
|
|
|
|
typedef typename unique_ptr<_T2, _D2>::pointer _P2;
|
2015-02-06 07:01:40 +08:00
|
|
|
typedef typename common_type<_P1, _P2>::type _Vp;
|
|
|
|
return less<_Vp>()(__x.get(), __y.get());
|
2012-02-22 05:02:58 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
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);}
|
|
|
|
|
2012-02-22 05:02:58 +08:00
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2012-07-08 04:56:04 +08:00
|
|
|
operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
|
2012-02-22 05:02:58 +08:00
|
|
|
{
|
|
|
|
return !__x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2012-07-08 04:56:04 +08:00
|
|
|
operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
|
2012-02-22 05:02:58 +08:00
|
|
|
{
|
|
|
|
return !__x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2012-07-08 04:56:04 +08:00
|
|
|
operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
|
2012-02-22 05:02:58 +08:00
|
|
|
{
|
|
|
|
return static_cast<bool>(__x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2012-07-08 04:56:04 +08:00
|
|
|
operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
|
2012-02-22 05:02:58 +08:00
|
|
|
{
|
|
|
|
return static_cast<bool>(__x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
|
|
|
|
{
|
|
|
|
typedef typename unique_ptr<_T1, _D1>::pointer _P1;
|
|
|
|
return less<_P1>()(__x.get(), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
|
|
|
|
{
|
|
|
|
typedef typename unique_ptr<_T1, _D1>::pointer _P1;
|
|
|
|
return less<_P1>()(nullptr, __x.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
|
|
|
|
{
|
|
|
|
return nullptr < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
|
|
|
|
{
|
|
|
|
return __x < nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
|
|
|
|
{
|
|
|
|
return !(nullptr < __x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
|
|
|
|
{
|
|
|
|
return !(__x < nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
|
|
|
|
{
|
|
|
|
return !(__x < nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _D1>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
|
|
|
|
{
|
|
|
|
return !(nullptr < __x);
|
|
|
|
}
|
|
|
|
|
2013-07-02 02:16:03 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
struct __unique_if
|
|
|
|
{
|
|
|
|
typedef unique_ptr<_Tp> __unique_single;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
struct __unique_if<_Tp[]>
|
|
|
|
{
|
|
|
|
typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class _Tp, size_t _Np>
|
|
|
|
struct __unique_if<_Tp[_Np]>
|
|
|
|
{
|
|
|
|
typedef void __unique_array_known_bound;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class _Tp, class... _Args>
|
2013-07-03 04:06:09 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2013-07-02 02:16:03 +08:00
|
|
|
typename __unique_if<_Tp>::__unique_single
|
|
|
|
make_unique(_Args&&... __args)
|
|
|
|
{
|
|
|
|
return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2013-07-03 04:06:09 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2013-07-02 02:16:03 +08:00
|
|
|
typename __unique_if<_Tp>::__unique_array_unknown_bound
|
|
|
|
make_unique(size_t __n)
|
|
|
|
{
|
|
|
|
typedef typename remove_extent<_Tp>::type _Up;
|
|
|
|
return unique_ptr<_Tp>(new _Up[__n]());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class... _Args>
|
|
|
|
typename __unique_if<_Tp>::__unique_array_known_bound
|
|
|
|
make_unique(_Args&&...) = delete;
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STD_VER > 11
|
|
|
|
|
2010-06-04 00:42:57 +08:00
|
|
|
template <class _Tp, class _Dp>
|
2017-01-21 08:02:12 +08:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
|
2017-01-21 08:02:12 +08:00
|
|
|
#else
|
|
|
|
struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
|
2019-06-24 04:47:21 +08:00
|
|
|
unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
|
2017-01-21 08:02:12 +08:00
|
|
|
#endif
|
2010-06-04 00:42:57 +08:00
|
|
|
{
|
|
|
|
typedef unique_ptr<_Tp, _Dp> argument_type;
|
|
|
|
typedef size_t result_type;
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-03-23 10:40:28 +08:00
|
|
|
result_type operator()(const argument_type& __ptr) const
|
2010-06-04 00:42:57 +08:00
|
|
|
{
|
|
|
|
typedef typename argument_type::pointer pointer;
|
|
|
|
return hash<pointer>()(__ptr.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __destruct_n
|
|
|
|
{
|
|
|
|
private:
|
2017-06-01 10:29:37 +08:00
|
|
|
size_t __size_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
|
2017-06-01 10:29:37 +08:00
|
|
|
{for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
|
2017-06-01 10:29:37 +08:00
|
|
|
{++__size_;}
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
|
|
|
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
|
2017-06-01 10:29:37 +08:00
|
|
|
{__size_ = __s;}
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
|
|
|
public:
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
|
2017-06-01 10:29:37 +08:00
|
|
|
: __size_(__s) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
|
2010-11-20 06:17:28 +08:00
|
|
|
{__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
|
2010-11-20 06:17:28 +08:00
|
|
|
{__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-28 22:41:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
|
2010-11-20 06:17:28 +08:00
|
|
|
{__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
class __allocator_destructor
|
|
|
|
{
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2019-06-12 10:03:31 +08:00
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
|
|
|
|
typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
|
|
|
_Alloc& __alloc_;
|
|
|
|
size_type __s_;
|
|
|
|
public:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __alloc_(__a), __s_(__s) {}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
void operator()(pointer __p) _NOEXCEPT
|
|
|
|
{__alloc_traits::deallocate(__alloc_, __p, __s_);}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _InputIterator, class _ForwardIterator>
|
|
|
|
_ForwardIterator
|
|
|
|
uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
|
|
|
|
{
|
|
|
|
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
_ForwardIterator __s = __r;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif
|
2015-05-19 23:01:48 +08:00
|
|
|
for (; __f != __l; ++__f, (void) ++__r)
|
|
|
|
::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
for (; __s != __r; ++__s)
|
|
|
|
__s->~value_type();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _InputIterator, class _Size, class _ForwardIterator>
|
|
|
|
_ForwardIterator
|
|
|
|
uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
|
|
|
|
{
|
|
|
|
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
_ForwardIterator __s = __r;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif
|
2015-05-19 23:01:48 +08:00
|
|
|
for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
|
|
|
|
::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
for (; __s != __r; ++__s)
|
|
|
|
__s->~value_type();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ForwardIterator, class _Tp>
|
|
|
|
void
|
|
|
|
uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
|
|
|
|
{
|
|
|
|
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
_ForwardIterator __s = __f;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
for (; __f != __l; ++__f)
|
2015-05-19 23:01:48 +08:00
|
|
|
::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
for (; __s != __f; ++__s)
|
|
|
|
__s->~value_type();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ForwardIterator, class _Size, class _Tp>
|
2010-11-19 00:13:03 +08:00
|
|
|
_ForwardIterator
|
2010-05-12 03:42:16 +08:00
|
|
|
uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
|
|
|
|
{
|
|
|
|
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
_ForwardIterator __s = __f;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif
|
2015-05-19 23:01:48 +08:00
|
|
|
for (; __n > 0; ++__f, (void) --__n)
|
|
|
|
::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
|
2011-12-30 01:45:35 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
for (; __s != __f; ++__s)
|
|
|
|
__s->~value_type();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2010-11-19 00:13:03 +08:00
|
|
|
return __f;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-07-24 11:51:39 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
|
2016-10-12 05:13:44 +08:00
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void destroy_at(_Tp* __loc) {
|
|
|
|
_LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
|
|
|
|
__loc->~_Tp();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ForwardIterator>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void destroy(_ForwardIterator __first, _ForwardIterator __last) {
|
|
|
|
for (; __first != __last; ++__first)
|
|
|
|
_VSTD::destroy_at(_VSTD::addressof(*__first));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ForwardIterator, class _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
|
|
|
|
for (; __n > 0; (void)++__first, --__n)
|
|
|
|
_VSTD::destroy_at(_VSTD::addressof(*__first));
|
|
|
|
return __first;
|
|
|
|
}
|
|
|
|
|
2016-07-24 11:51:39 +08:00
|
|
|
template <class _ForwardIterator>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
|
|
|
|
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
|
2016-10-12 05:13:44 +08:00
|
|
|
auto __idx = __first;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
for (; __idx != __last; ++__idx)
|
|
|
|
::new((void*)_VSTD::addressof(*__idx)) _Vt;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
_VSTD::destroy(__first, __idx);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-24 11:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ForwardIterator, class _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
|
|
|
|
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
|
2016-10-12 05:13:44 +08:00
|
|
|
auto __idx = __first;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
for (; __n > 0; (void)++__idx, --__n)
|
|
|
|
::new((void*)_VSTD::addressof(*__idx)) _Vt;
|
|
|
|
return __idx;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
_VSTD::destroy(__first, __idx);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-24 11:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class _ForwardIterator>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
|
|
|
|
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
|
2016-10-12 05:13:44 +08:00
|
|
|
auto __idx = __first;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
for (; __idx != __last; ++__idx)
|
|
|
|
::new((void*)_VSTD::addressof(*__idx)) _Vt();
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
_VSTD::destroy(__first, __idx);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-24 11:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ForwardIterator, class _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
|
|
|
|
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
|
2016-10-12 05:13:44 +08:00
|
|
|
auto __idx = __first;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
for (; __n > 0; (void)++__idx, --__n)
|
|
|
|
::new((void*)_VSTD::addressof(*__idx)) _Vt();
|
|
|
|
return __idx;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
_VSTD::destroy(__first, __idx);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-24 11:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class _InputIt, class _ForwardIt>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-10-12 05:13:44 +08:00
|
|
|
_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
|
2016-07-24 11:51:39 +08:00
|
|
|
using _Vt = typename iterator_traits<_ForwardIt>::value_type;
|
2016-10-12 05:13:44 +08:00
|
|
|
auto __idx = __first_res;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
for (; __first != __last; (void)++__idx, ++__first)
|
|
|
|
::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
|
|
|
|
return __idx;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
_VSTD::destroy(__first_res, __idx);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-24 11:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _InputIt, class _Size, class _ForwardIt>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<_InputIt, _ForwardIt>
|
2016-10-12 05:13:44 +08:00
|
|
|
uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
|
2016-07-24 11:51:39 +08:00
|
|
|
using _Vt = typename iterator_traits<_ForwardIt>::value_type;
|
2016-10-12 05:13:44 +08:00
|
|
|
auto __idx = __first_res;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
for (; __n > 0; ++__idx, (void)++__first, --__n)
|
|
|
|
::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
|
|
|
|
return {__first, __idx};
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
_VSTD::destroy(__first_res, __idx);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-24 11:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STD_VER > 14
|
|
|
|
|
2017-01-17 10:46:33 +08:00
|
|
|
// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
|
|
|
|
// should be sufficient for thread safety.
|
2017-02-17 16:37:03 +08:00
|
|
|
// See https://bugs.llvm.org/show_bug.cgi?id=22803
|
2017-01-17 10:46:33 +08:00
|
|
|
#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
|
|
|
|
&& defined(__ATOMIC_RELAXED) \
|
|
|
|
&& defined(__ATOMIC_ACQ_REL)
|
|
|
|
# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
|
2019-04-26 04:02:10 +08:00
|
|
|
#elif defined(_LIBCPP_COMPILER_GCC)
|
2017-01-17 10:46:33 +08:00
|
|
|
# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _Tp
|
|
|
|
__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
|
|
|
|
return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
|
|
|
|
#else
|
|
|
|
return __t += 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _Tp
|
|
|
|
__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
|
|
|
|
return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
|
|
|
|
#else
|
|
|
|
return __t -= 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
|
2010-05-12 03:42:16 +08:00
|
|
|
: public std::exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual ~bad_weak_ptr() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
|
2016-08-25 23:09:01 +08:00
|
|
|
void __throw_bad_weak_ptr()
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
throw bad_weak_ptr();
|
|
|
|
#else
|
|
|
|
_VSTD::abort();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
class _LIBCPP_TYPE_VIS __shared_count
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__shared_count(const __shared_count&);
|
|
|
|
__shared_count& operator=(const __shared_count&);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
long __shared_owners_;
|
|
|
|
virtual ~__shared_count();
|
|
|
|
private:
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT = 0;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
public:
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
explicit __shared_count(long __refs = 0) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __shared_owners_(__refs) {}
|
|
|
|
|
2018-08-01 10:08:59 +08:00
|
|
|
#if defined(_LIBCPP_BUILDING_LIBRARY) && \
|
2017-01-17 11:16:26 +08:00
|
|
|
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
|
2017-01-17 11:05:31 +08:00
|
|
|
void __add_shared() _NOEXCEPT;
|
|
|
|
bool __release_shared() _NOEXCEPT;
|
2017-01-17 10:46:33 +08:00
|
|
|
#else
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __add_shared() _NOEXCEPT {
|
|
|
|
__libcpp_atomic_refcount_increment(__shared_owners_);
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool __release_shared() _NOEXCEPT {
|
|
|
|
if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
|
|
|
|
__on_zero_shared();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2015-07-07 08:27:16 +08:00
|
|
|
long use_count() const _NOEXCEPT {
|
|
|
|
return __libcpp_relaxed_load(&__shared_owners_) + 1;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
class _LIBCPP_TYPE_VIS __shared_weak_count
|
2010-05-12 03:42:16 +08:00
|
|
|
: private __shared_count
|
|
|
|
{
|
|
|
|
long __shared_weak_owners_;
|
|
|
|
|
|
|
|
public:
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __shared_count(__refs),
|
|
|
|
__shared_weak_owners_(__refs) {}
|
|
|
|
protected:
|
|
|
|
virtual ~__shared_weak_count();
|
|
|
|
|
|
|
|
public:
|
2018-08-01 10:08:59 +08:00
|
|
|
#if defined(_LIBCPP_BUILDING_LIBRARY) && \
|
2017-01-17 11:16:26 +08:00
|
|
|
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
|
2017-01-17 11:05:31 +08:00
|
|
|
void __add_shared() _NOEXCEPT;
|
|
|
|
void __add_weak() _NOEXCEPT;
|
|
|
|
void __release_shared() _NOEXCEPT;
|
2017-01-17 10:46:33 +08:00
|
|
|
#else
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __add_shared() _NOEXCEPT {
|
|
|
|
__shared_count::__add_shared();
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __add_weak() _NOEXCEPT {
|
|
|
|
__libcpp_atomic_refcount_increment(__shared_weak_owners_);
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __release_shared() _NOEXCEPT {
|
|
|
|
if (__shared_count::__release_shared())
|
|
|
|
__release_weak();
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-28 22:41:13 +08:00
|
|
|
void __release_weak() _NOEXCEPT;
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
long use_count() const _NOEXCEPT {return __shared_count::use_count();}
|
|
|
|
__shared_weak_count* lock() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-02-25 23:50:36 +08:00
|
|
|
// Define the function out only if we build static libc++ without RTTI.
|
|
|
|
// Otherwise we may break clients who need to compile their projects with
|
|
|
|
// -fno-rtti and yet link against a libc++.dylib compiled
|
|
|
|
// without -fno-rtti.
|
|
|
|
#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
|
2013-02-25 23:50:36 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Dp, class _Alloc>
|
|
|
|
class __shared_ptr_pointer
|
|
|
|
: public __shared_weak_count
|
|
|
|
{
|
|
|
|
__compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
|
|
|
|
public:
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_RTTI
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
|
2010-08-12 01:04:31 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
|
|
|
virtual void __on_zero_shared_weak() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_RTTI
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Dp, class _Alloc>
|
|
|
|
const void*
|
2011-05-28 22:41:13 +08:00
|
|
|
__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2017-05-04 09:06:56 +08:00
|
|
|
return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_RTTI
|
2010-08-12 01:04:31 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Dp, class _Alloc>
|
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__data_.first().second()(__data_.first().first());
|
|
|
|
__data_.first().second().~_Dp();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Dp, class _Alloc>
|
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2015-02-06 07:01:40 +08:00
|
|
|
typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
|
|
|
|
typedef allocator_traits<_Al> _ATraits;
|
2014-10-23 12:12:28 +08:00
|
|
|
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
|
|
|
|
|
2015-02-06 07:01:40 +08:00
|
|
|
_Al __a(__data_.second());
|
2010-05-12 03:42:16 +08:00
|
|
|
__data_.second().~_Alloc();
|
2014-10-23 12:12:28 +08:00
|
|
|
__a.deallocate(_PTraits::pointer_to(*this), 1);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
class __shared_ptr_emplace
|
|
|
|
: public __shared_weak_count
|
|
|
|
{
|
|
|
|
__compressed_pair<_Alloc, _Tp> __data_;
|
|
|
|
public:
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_emplace(_Alloc __a)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __data_(_VSTD::move(__a)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class ..._Args>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
|
2011-12-20 01:58:44 +08:00
|
|
|
: __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
|
|
|
|
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
#else // _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_emplace(_Alloc __a)
|
|
|
|
: __data_(__a) {}
|
|
|
|
|
|
|
|
template <class _A0>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_emplace(_Alloc __a, _A0& __a0)
|
|
|
|
: __data_(__a, _Tp(__a0)) {}
|
|
|
|
|
|
|
|
template <class _A0, class _A1>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
|
|
|
|
: __data_(__a, _Tp(__a0, __a1)) {}
|
|
|
|
|
|
|
|
template <class _A0, class _A1, class _A2>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
|
|
|
|
: __data_(__a, _Tp(__a0, __a1, __a2)) {}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
|
|
|
|
private:
|
2011-05-28 22:41:13 +08:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
|
|
|
virtual void __on_zero_shared_weak() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-08-28 21:29:30 +08:00
|
|
|
_Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__data_.second().~_Tp();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2015-02-06 07:01:40 +08:00
|
|
|
typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
|
|
|
|
typedef allocator_traits<_Al> _ATraits;
|
2014-10-23 12:12:28 +08:00
|
|
|
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
|
2015-02-06 07:01:40 +08:00
|
|
|
_Al __a(__data_.first());
|
2010-05-12 03:42:16 +08:00
|
|
|
__data_.first().~_Alloc();
|
2014-10-23 12:12:28 +08:00
|
|
|
__a.deallocate(_PTraits::pointer_to(*this), 1);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2017-05-25 23:43:31 +08:00
|
|
|
struct __shared_ptr_dummy_rebind_allocator_type;
|
|
|
|
template <>
|
|
|
|
class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template <class _Other>
|
|
|
|
struct rebind
|
|
|
|
{
|
|
|
|
typedef allocator<_Other> other;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS shared_ptr
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
public:
|
|
|
|
typedef _Tp element_type;
|
2017-01-11 00:59:33 +08:00
|
|
|
|
2016-06-27 09:02:43 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
typedef weak_ptr<_Tp> weak_type;
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
|
|
|
element_type* __ptr_;
|
|
|
|
__shared_weak_count* __cntrl_;
|
|
|
|
|
|
|
|
struct __nat {int __for_bool_;};
|
|
|
|
public:
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp>
|
|
|
|
explicit shared_ptr(_Yp* __p,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
|
|
|
|
template<class _Yp, class _Dp>
|
|
|
|
shared_ptr(_Yp* __p, _Dp __d,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
|
|
|
|
template<class _Yp, class _Dp, class _Alloc>
|
|
|
|
shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
|
|
|
|
template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
|
2015-11-07 09:22:13 +08:00
|
|
|
template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr(const shared_ptr& __r) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr(const shared_ptr<_Yp>& __r,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT;
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr(shared_ptr&& __r) _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT;
|
2010-09-05 07:28:19 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp>
|
|
|
|
shared_ptr(auto_ptr<_Yp>&& __r,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
|
2010-08-22 08:02:43 +08:00
|
|
|
#else
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp>
|
|
|
|
shared_ptr(auto_ptr<_Yp> __r,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2014-01-31 17:30:46 +08:00
|
|
|
template <class _Yp, class _Dp>
|
|
|
|
shared_ptr(unique_ptr<_Yp, _Dp>&&,
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_lvalue_reference<_Dp>::value &&
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
__nat
|
|
|
|
>::type = __nat());
|
|
|
|
template <class _Yp, class _Dp>
|
|
|
|
shared_ptr(unique_ptr<_Yp, _Dp>&&,
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_lvalue_reference<_Dp>::value &&
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
__nat
|
|
|
|
>::type = __nat());
|
2010-09-05 07:28:19 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2014-01-31 17:30:46 +08:00
|
|
|
template <class _Yp, class _Dp>
|
|
|
|
shared_ptr(unique_ptr<_Yp, _Dp>,
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_lvalue_reference<_Dp>::value &&
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
__nat
|
|
|
|
>::type = __nat());
|
|
|
|
template <class _Yp, class _Dp>
|
|
|
|
shared_ptr(unique_ptr<_Yp, _Dp>,
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_lvalue_reference<_Dp>::value &&
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
__nat
|
|
|
|
>::type = __nat());
|
2010-09-05 07:28:19 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
~shared_ptr();
|
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
|
2012-01-03 01:56:02 +08:00
|
|
|
template<class _Yp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
shared_ptr&
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
|
2012-01-03 01:56:02 +08:00
|
|
|
template<class _Yp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
shared_ptr<_Tp>&
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(shared_ptr<_Yp>&& __r);
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2012-01-03 01:56:02 +08:00
|
|
|
template<class _Yp>
|
2016-04-22 06:54:21 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
2013-09-14 07:56:00 +08:00
|
|
|
shared_ptr
|
|
|
|
>::type&
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(auto_ptr<_Yp>&& __r);
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-09-05 07:28:19 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2012-01-03 01:56:02 +08:00
|
|
|
template<class _Yp>
|
2016-04-22 06:54:21 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
shared_ptr&
|
|
|
|
>::type
|
|
|
|
operator=(auto_ptr<_Yp> __r);
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
2012-01-03 01:56:02 +08:00
|
|
|
template <class _Yp, class _Dp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
shared_ptr&
|
|
|
|
>::type
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(unique_ptr<_Yp, _Dp>&& __r);
|
2010-09-05 07:28:19 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2015-12-10 06:32:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(unique_ptr<_Yp, _Dp> __r);
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
void swap(shared_ptr& __r) _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
void reset() _NOEXCEPT;
|
2012-01-03 01:56:02 +08:00
|
|
|
template<class _Yp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
reset(_Yp* __p);
|
|
|
|
template<class _Yp, class _Dp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
reset(_Yp* __p, _Dp __d);
|
|
|
|
template<class _Yp, class _Dp, class _Alloc>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
reset(_Yp* __p, _Dp __d, _Alloc __a);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
element_type* get() const _NOEXCEPT {return __ptr_;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
|
|
|
|
{return *__ptr_;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
element_type* operator->() const _NOEXCEPT {return __ptr_;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
bool unique() const _NOEXCEPT {return use_count() == 1;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-02-22 05:46:43 +08:00
|
|
|
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Up>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __cntrl_ < __p.__cntrl_;}
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Up>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __cntrl_ < __p.__cntrl_;}
|
2012-07-30 09:40:57 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
__owner_equivalent(const shared_ptr& __p) const
|
|
|
|
{return __cntrl_ == __p.__cntrl_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_RTTI
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Dp>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
_Dp* __get_deleter() const _NOEXCEPT
|
2017-06-15 00:54:43 +08:00
|
|
|
{return static_cast<_Dp*>(__cntrl_
|
2017-08-20 18:38:55 +08:00
|
|
|
? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
|
2017-06-15 00:54:43 +08:00
|
|
|
: nullptr);}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_RTTI
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2019-10-22 23:16:49 +08:00
|
|
|
template<class _Yp, class _CntrlBlk>
|
|
|
|
static shared_ptr<_Tp>
|
|
|
|
__create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
|
|
|
|
{
|
|
|
|
shared_ptr<_Tp> __r;
|
|
|
|
__r.__ptr_ = __p;
|
|
|
|
__r.__cntrl_ = __cntrl;
|
|
|
|
__r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
|
|
|
|
return __r;
|
|
|
|
}
|
2019-08-19 23:47:16 +08:00
|
|
|
|
|
|
|
template<class _Alloc, class ..._Args>
|
|
|
|
static
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
allocate_shared(const _Alloc& __a, _Args&& ...__args);
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
2017-05-25 23:43:31 +08:00
|
|
|
template <class _Yp, bool = is_function<_Yp>::value>
|
|
|
|
struct __shared_ptr_default_allocator
|
|
|
|
{
|
|
|
|
typedef allocator<_Yp> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Yp>
|
|
|
|
struct __shared_ptr_default_allocator<_Yp, true>
|
|
|
|
{
|
|
|
|
typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
|
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-06-27 07:56:32 +08:00
|
|
|
template <class _Yp, class _OrigPtr>
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-05-11 03:35:49 +08:00
|
|
|
typename enable_if<is_convertible<_OrigPtr*,
|
|
|
|
const enable_shared_from_this<_Yp>*
|
|
|
|
>::value,
|
|
|
|
void>::type
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(const enable_shared_from_this<_Yp>* __e,
|
|
|
|
_OrigPtr* __ptr) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-06-27 07:56:32 +08:00
|
|
|
typedef typename remove_cv<_Yp>::type _RawYp;
|
2016-06-02 08:15:35 +08:00
|
|
|
if (__e && __e->__weak_this_.expired())
|
2015-06-19 23:54:13 +08:00
|
|
|
{
|
2016-06-27 07:56:32 +08:00
|
|
|
__e->__weak_this_ = shared_ptr<_RawYp>(*this,
|
|
|
|
const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
|
2015-06-19 23:54:13 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2017-05-25 23:43:31 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
|
|
|
|
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-05-11 03:35:49 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(0),
|
|
|
|
__cntrl_(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(0),
|
|
|
|
__cntrl_(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp>
|
|
|
|
shared_ptr<_Tp>::shared_ptr(_Yp* __p,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__p)
|
|
|
|
{
|
|
|
|
unique_ptr<_Yp> __hold(__p);
|
2017-05-25 23:43:31 +08:00
|
|
|
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
|
|
|
|
typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
|
|
|
|
__cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
|
2010-05-12 03:42:16 +08:00
|
|
|
__hold.release();
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(__p, __p);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp, class _Dp>
|
|
|
|
shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__p)
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2017-05-25 23:43:31 +08:00
|
|
|
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
|
|
|
|
typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
|
|
|
|
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(__p, __p);
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__d(__p);
|
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Dp>
|
|
|
|
shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
|
|
|
|
: __ptr_(0)
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2017-05-25 23:43:31 +08:00
|
|
|
typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
|
|
|
|
typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
|
|
|
|
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__d(__p);
|
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp, class _Dp, class _Alloc>
|
|
|
|
shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
|
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__p)
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
|
2014-10-23 12:12:28 +08:00
|
|
|
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __allocator_destructor<_A2> _D2;
|
|
|
|
_A2 __a2(__a);
|
|
|
|
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
|
2014-10-23 12:12:28 +08:00
|
|
|
::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
|
|
|
|
_CntrlBlk(__p, __d, __a);
|
|
|
|
__cntrl_ = _VSTD::addressof(*__hold2.release());
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(__p, __p);
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__d(__p);
|
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
|
2014-10-23 12:12:28 +08:00
|
|
|
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __allocator_destructor<_A2> _D2;
|
|
|
|
_A2 __a2(__a);
|
|
|
|
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
|
2014-10-23 12:12:28 +08:00
|
|
|
::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
|
|
|
|
_CntrlBlk(__p, __d, __a);
|
|
|
|
__cntrl_ = _VSTD::addressof(*__hold2.release());
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__d(__p);
|
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__p),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__add_shared();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__add_shared();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__add_shared();
|
|
|
|
}
|
|
|
|
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
__r.__ptr_ = 0;
|
|
|
|
__r.__cntrl_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
__r.__ptr_ = 0;
|
|
|
|
__r.__cntrl_ = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-05 07:28:19 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
2014-01-31 17:30:46 +08:00
|
|
|
template<class _Yp>
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2014-01-31 17:30:46 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
|
2010-05-12 03:42:16 +08:00
|
|
|
#else
|
2014-01-31 17:30:46 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
2014-01-31 17:30:46 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.get())
|
|
|
|
{
|
|
|
|
typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
|
|
|
|
__cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(__r.get(), __r.get());
|
2010-05-12 03:42:16 +08:00
|
|
|
__r.release();
|
|
|
|
}
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
2014-01-31 17:30:46 +08:00
|
|
|
template <class _Yp, class _Dp>
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
|
|
|
|
#else
|
|
|
|
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
|
|
|
|
#endif
|
2014-01-31 17:30:46 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_lvalue_reference<_Dp>::value &&
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
__nat
|
|
|
|
>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.get())
|
|
|
|
{
|
2015-05-10 21:59:45 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
if (__ptr_ == nullptr)
|
|
|
|
__cntrl_ = nullptr;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2017-05-25 23:43:31 +08:00
|
|
|
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
|
|
|
|
typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
|
|
|
|
__cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(__r.get(), __r.get());
|
2015-05-10 21:59:45 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
__r.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2014-01-31 17:30:46 +08:00
|
|
|
template <class _Yp, class _Dp>
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
|
|
|
|
#else
|
|
|
|
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
|
|
|
|
#endif
|
2014-01-31 17:30:46 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_lvalue_reference<_Dp>::value &&
|
|
|
|
!is_array<_Yp>::value &&
|
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
|
|
|
|
__nat
|
|
|
|
>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.get())
|
|
|
|
{
|
2015-05-10 21:59:45 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
if (__ptr_ == nullptr)
|
|
|
|
__cntrl_ = nullptr;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2017-05-25 23:43:31 +08:00
|
|
|
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
|
2015-05-10 21:59:45 +08:00
|
|
|
typedef __shared_ptr_pointer<_Yp*,
|
|
|
|
reference_wrapper<typename remove_reference<_Dp>::type>,
|
2017-05-25 23:43:31 +08:00
|
|
|
_AllocT > _CntrlBlk;
|
|
|
|
__cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
|
2016-06-27 07:56:32 +08:00
|
|
|
__enable_weak_this(__r.get(), __r.get());
|
2015-05-10 21:59:45 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
__r.release();
|
|
|
|
}
|
|
|
|
|
2019-08-19 23:47:16 +08:00
|
|
|
template<class _Tp>
|
|
|
|
template<class _Alloc, class ..._Args>
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
|
|
|
|
{
|
|
|
|
static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
|
|
|
|
typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
|
|
|
|
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
|
|
|
|
typedef __allocator_destructor<_A2> _D2;
|
|
|
|
_A2 __a2(__a);
|
|
|
|
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
|
|
|
|
::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
|
|
|
|
_CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
|
|
|
|
shared_ptr<_Tp> __r;
|
|
|
|
__r.__ptr_ = __hold2.get()->get();
|
|
|
|
__r.__cntrl_ = _VSTD::addressof(*__hold2.release());
|
|
|
|
__r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
|
|
|
shared_ptr<_Tp>::~shared_ptr()
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__release_shared();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>&
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
shared_ptr(__r).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2017-01-11 00:59:33 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
shared_ptr<_Tp>&
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
shared_ptr(__r).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-05 07:28:19 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>&
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
shared_ptr(_VSTD::move(__r)).swap(*this);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2017-01-11 00:59:33 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
shared_ptr<_Tp>&
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
shared_ptr(_VSTD::move(__r)).swap(*this);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
2017-01-11 00:59:33 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2013-09-14 07:56:00 +08:00
|
|
|
shared_ptr<_Tp>
|
|
|
|
>::type&
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
shared_ptr(_VSTD::move(__r)).swap(*this);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template <class _Yp, class _Dp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
2017-08-20 18:38:55 +08:00
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
shared_ptr<_Tp>&
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
shared_ptr(_VSTD::move(__r)).swap(*this);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-05 07:28:19 +08:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-25 06:22:33 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
2017-01-11 02:40:01 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
shared_ptr<_Tp>&
|
|
|
|
>::type
|
2010-08-22 08:02:43 +08:00
|
|
|
shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
shared_ptr(__r).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-01-25 06:22:33 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template <class _Yp, class _Dp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Yp>::value &&
|
2017-08-20 18:38:55 +08:00
|
|
|
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
|
2017-01-11 02:40:01 +08:00
|
|
|
typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
shared_ptr<_Tp>&
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
shared_ptr(_VSTD::move(__r)).swap(*this);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-05 07:28:19 +08:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__ptr_, __r.__ptr_);
|
|
|
|
_VSTD::swap(__cntrl_, __r.__cntrl_);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp>::reset() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
shared_ptr().swap(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2017-01-11 00:59:33 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
void
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::reset(_Yp* __p)
|
|
|
|
{
|
|
|
|
shared_ptr(__p).swap(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp, class _Dp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2017-01-11 00:59:33 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
void
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
|
|
|
|
{
|
|
|
|
shared_ptr(__p, __d).swap(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp, class _Dp, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2017-01-11 00:59:33 +08:00
|
|
|
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
|
2012-01-03 01:56:02 +08:00
|
|
|
void
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
|
|
|
|
{
|
|
|
|
shared_ptr(__p, __d, __a).swap(*this);
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template<class _Tp, class ..._Args>
|
2010-05-12 03:42:16 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Tp>::value,
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
make_shared(_Args&& ...__args)
|
|
|
|
{
|
2019-10-22 23:16:49 +08:00
|
|
|
static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared");
|
|
|
|
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, _VSTD::forward<_Args>(__args)...);
|
|
|
|
|
|
|
|
_Tp *__ptr = __hold2.get()->get();
|
|
|
|
return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template<class _Tp, class _Alloc, class ..._Args>
|
2010-05-12 03:42:16 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Tp>::value,
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
allocate_shared(const _Alloc& __a, _Args&& ...__args)
|
|
|
|
{
|
2019-08-19 23:47:16 +08:00
|
|
|
return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2011-05-28 22:41:13 +08:00
|
|
|
operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return __x.get() == __y.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2011-05-28 22:41:13 +08:00
|
|
|
operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2011-05-28 22:41:13 +08:00
|
|
|
operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2018-02-13 01:26:40 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 11
|
2015-02-06 07:01:40 +08:00
|
|
|
typedef typename common_type<_Tp*, _Up*>::type _Vp;
|
|
|
|
return less<_Vp>()(__x.get(), __y.get());
|
2018-02-13 01:26:40 +08:00
|
|
|
#else
|
|
|
|
return less<>()(__x.get(), __y.get());
|
|
|
|
#endif
|
|
|
|
|
2012-02-22 05:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !__x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !__x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return static_cast<bool>(__x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return static_cast<bool>(__x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return less<_Tp*>()(__x.get(), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return less<_Tp*>()(nullptr, __x.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return nullptr < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return __x < nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !(nullptr < __x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !(__x < nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !(__x < nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return !(nullptr < __x);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Tp>::value && !is_array<_Up>::value,
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
!is_array<_Tp>::value && !is_array<_Up>::value,
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
_Tp* __p = dynamic_cast<_Tp*>(__r.get());
|
|
|
|
return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp, class _Up>
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_array<_Tp>::value == is_array<_Up>::value,
|
|
|
|
shared_ptr<_Tp>
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2012-01-03 01:56:02 +08:00
|
|
|
typedef typename remove_extent<_Tp>::type _RTp;
|
|
|
|
return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_RTTI
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Dp, class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
_Dp*
|
2011-05-28 22:41:13 +08:00
|
|
|
get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return __p.template __get_deleter<_Dp>();
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_RTTI
|
2010-08-12 01:04:31 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS weak_ptr
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
public:
|
|
|
|
typedef _Tp element_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
|
|
|
element_type* __ptr_;
|
|
|
|
__shared_weak_count* __cntrl_;
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
public:
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
|
2011-05-28 22:41:13 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
|
|
|
|
_NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr(weak_ptr const& __r) _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
|
2011-05-28 22:41:13 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
|
|
|
|
_NOEXCEPT;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
weak_ptr(weak_ptr&& __r) _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
|
|
|
|
_NOEXCEPT;
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-22 08:02:43 +08:00
|
|
|
~weak_ptr();
|
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
|
2012-01-03 01:56:02 +08:00
|
|
|
template<class _Yp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
weak_ptr&
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
|
|
|
|
template<class _Yp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
weak_ptr&
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
|
|
|
template<class _Yp>
|
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, element_type*>::value,
|
|
|
|
weak_ptr&
|
|
|
|
>::type
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-01-03 01:56:02 +08:00
|
|
|
operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
void swap(weak_ptr& __r) _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
void reset() _NOEXCEPT;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
long use_count() const _NOEXCEPT
|
|
|
|
{return __cntrl_ ? __cntrl_->use_count() : 0;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
bool expired() const _NOEXCEPT
|
|
|
|
{return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
|
|
|
|
shared_ptr<_Tp> lock() const _NOEXCEPT;
|
2010-09-23 00:48:34 +08:00
|
|
|
template<class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __cntrl_ < __r.__cntrl_;}
|
2010-09-23 00:48:34 +08:00
|
|
|
template<class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __cntrl_ < __r.__cntrl_;}
|
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
|
|
|
|
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(0),
|
|
|
|
__cntrl_(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__add_weak();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
|
2011-05-22 08:09:02 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__add_weak();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
|
2011-05-22 08:09:02 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
|
2011-05-28 22:41:13 +08:00
|
|
|
_NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__add_weak();
|
|
|
|
}
|
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
|
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
__r.__ptr_ = 0;
|
|
|
|
__r.__cntrl_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
|
|
|
|
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
|
|
|
|
_NOEXCEPT
|
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_)
|
|
|
|
{
|
|
|
|
__r.__ptr_ = 0;
|
|
|
|
__r.__cntrl_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
|
|
|
weak_ptr<_Tp>::~weak_ptr()
|
|
|
|
{
|
|
|
|
if (__cntrl_)
|
|
|
|
__cntrl_->__release_weak();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
weak_ptr<_Tp>&
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
weak_ptr(__r).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2010-08-22 08:02:43 +08:00
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, _Tp*>::value,
|
|
|
|
weak_ptr<_Tp>&
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
weak_ptr(__r).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-01-03 01:56:02 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
weak_ptr<_Tp>&
|
2012-01-03 01:56:02 +08:00
|
|
|
weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
|
|
|
|
{
|
|
|
|
weak_ptr(_VSTD::move(__r)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, _Tp*>::value,
|
|
|
|
weak_ptr<_Tp>&
|
|
|
|
>::type
|
|
|
|
weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
|
|
|
|
{
|
|
|
|
weak_ptr(_VSTD::move(__r)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2012-01-03 01:56:02 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
is_convertible<_Yp*, _Tp*>::value,
|
|
|
|
weak_ptr<_Tp>&
|
|
|
|
>::type
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
weak_ptr(__r).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__ptr_, __r.__ptr_);
|
|
|
|
_VSTD::swap(__cntrl_, __r.__cntrl_);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::reset() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
weak_ptr().swap(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
template<class _Yp>
|
|
|
|
shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
|
2017-01-11 00:59:33 +08:00
|
|
|
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__r.__ptr_),
|
|
|
|
__cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
|
|
|
|
{
|
|
|
|
if (__cntrl_ == 0)
|
2016-08-25 23:09:01 +08:00
|
|
|
__throw_bad_weak_ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class _Tp>
|
|
|
|
shared_ptr<_Tp>
|
2011-05-28 22:41:13 +08:00
|
|
|
weak_ptr<_Tp>::lock() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
shared_ptr<_Tp> __r;
|
|
|
|
__r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
|
|
|
|
if (__r.__cntrl_)
|
|
|
|
__r.__ptr_ = __ptr_;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2015-11-12 23:56:44 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template <class _Tp = void> struct owner_less;
|
|
|
|
#else
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp> struct owner_less;
|
2015-11-12 23:56:44 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
|
2010-05-12 03:42:16 +08:00
|
|
|
: binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
|
2010-08-22 08:02:43 +08:00
|
|
|
{
|
|
|
|
typedef bool result_type;
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.owner_before(__y);}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.owner_before(__y);}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.owner_before(__y);}
|
2010-08-22 08:02:43 +08:00
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
|
2010-05-12 03:42:16 +08:00
|
|
|
: binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
typedef bool result_type;
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.owner_before(__y);}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.owner_before(__y);}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.owner_before(__y);}
|
|
|
|
};
|
|
|
|
|
2015-11-12 23:56:44 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template <>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS owner_less<void>
|
2015-11-12 23:56:44 +08:00
|
|
|
{
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
|
2015-11-12 23:56:44 +08:00
|
|
|
{return __x.owner_before(__y);}
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
|
2015-11-12 23:56:44 +08:00
|
|
|
{return __x.owner_before(__y);}
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
|
2015-11-12 23:56:44 +08:00
|
|
|
{return __x.owner_before(__y);}
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-04-12 01:08:53 +08:00
|
|
|
bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
|
2015-11-12 23:56:44 +08:00
|
|
|
{return __x.owner_before(__y);}
|
|
|
|
typedef void is_transparent;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template<class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
mutable weak_ptr<_Tp> __weak_this_;
|
2010-08-22 08:02:43 +08:00
|
|
|
protected:
|
2012-07-08 04:56:04 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
2011-05-28 22:41:13 +08:00
|
|
|
enable_shared_from_this() _NOEXCEPT {}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
|
|
|
|
{return *this;}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
~enable_shared_from_this() {}
|
2010-08-22 08:02:43 +08:00
|
|
|
public:
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp> shared_from_this()
|
|
|
|
{return shared_ptr<_Tp>(__weak_this_);}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
shared_ptr<_Tp const> shared_from_this() const
|
|
|
|
{return shared_ptr<const _Tp>(__weak_this_);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-06-02 08:15:35 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
weak_ptr<_Tp> weak_from_this() _NOEXCEPT
|
|
|
|
{ return __weak_this_; }
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
|
|
|
|
{ return __weak_this_; }
|
|
|
|
#endif // _LIBCPP_STD_VER > 14
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Up> friend class shared_ptr;
|
|
|
|
};
|
|
|
|
|
2010-06-04 00:42:57 +08:00
|
|
|
template <class _Tp>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
|
2010-06-04 00:42:57 +08:00
|
|
|
{
|
|
|
|
typedef shared_ptr<_Tp> argument_type;
|
|
|
|
typedef size_t result_type;
|
2017-01-21 08:02:12 +08:00
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-28 22:41:13 +08:00
|
|
|
result_type operator()(const argument_type& __ptr) const _NOEXCEPT
|
2010-06-04 00:42:57 +08:00
|
|
|
{
|
|
|
|
return hash<_Tp*>()(__ptr.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template<class _CharT, class _Traits, class _Yp>
|
2011-07-18 23:51:59 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
basic_ostream<_CharT, _Traits>&
|
2011-11-30 02:15:50 +08:00
|
|
|
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
|
2011-07-18 23:51:59 +08:00
|
|
|
|
2016-06-18 10:12:53 +08:00
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
|
2012-07-30 09:40:57 +08:00
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
class _LIBCPP_TYPE_VIS __sp_mut
|
2012-07-30 09:40:57 +08:00
|
|
|
{
|
2012-10-31 03:06:59 +08:00
|
|
|
void* __lx;
|
2012-07-30 09:40:57 +08:00
|
|
|
public:
|
|
|
|
void lock() _NOEXCEPT;
|
|
|
|
void unlock() _NOEXCEPT;
|
|
|
|
|
|
|
|
private:
|
|
|
|
_LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
|
|
|
|
__sp_mut(const __sp_mut&);
|
|
|
|
__sp_mut& operator=(const __sp_mut&);
|
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
|
2012-07-30 09:40:57 +08:00
|
|
|
};
|
|
|
|
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
|
|
|
__sp_mut& __get_sp_mut(const void*);
|
2012-07-30 09:40:57 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
atomic_is_lock_free(const shared_ptr<_Tp>*)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
shared_ptr<_Tp>
|
|
|
|
atomic_load(const shared_ptr<_Tp>* __p)
|
|
|
|
{
|
|
|
|
__sp_mut& __m = __get_sp_mut(__p);
|
|
|
|
__m.lock();
|
|
|
|
shared_ptr<_Tp> __q = *__p;
|
|
|
|
__m.unlock();
|
|
|
|
return __q;
|
|
|
|
}
|
2017-08-20 18:38:55 +08:00
|
|
|
|
2012-07-30 09:40:57 +08:00
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
shared_ptr<_Tp>
|
|
|
|
atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
|
|
|
|
{
|
|
|
|
return atomic_load(__p);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
void
|
|
|
|
atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
|
|
|
|
{
|
|
|
|
__sp_mut& __m = __get_sp_mut(__p);
|
|
|
|
__m.lock();
|
|
|
|
__p->swap(__r);
|
|
|
|
__m.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
void
|
|
|
|
atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
|
|
|
|
{
|
|
|
|
atomic_store(__p, __r);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
shared_ptr<_Tp>
|
|
|
|
atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
|
|
|
|
{
|
|
|
|
__sp_mut& __m = __get_sp_mut(__p);
|
|
|
|
__m.lock();
|
|
|
|
__p->swap(__r);
|
|
|
|
__m.unlock();
|
|
|
|
return __r;
|
|
|
|
}
|
2017-08-20 18:38:55 +08:00
|
|
|
|
2012-07-30 09:40:57 +08:00
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
shared_ptr<_Tp>
|
|
|
|
atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
|
|
|
|
{
|
|
|
|
return atomic_exchange(__p, __r);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
bool
|
|
|
|
atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
|
|
|
|
{
|
2016-05-19 01:50:13 +08:00
|
|
|
shared_ptr<_Tp> __temp;
|
2012-07-30 09:40:57 +08:00
|
|
|
__sp_mut& __m = __get_sp_mut(__p);
|
|
|
|
__m.lock();
|
|
|
|
if (__p->__owner_equivalent(*__v))
|
|
|
|
{
|
2016-05-19 01:50:13 +08:00
|
|
|
_VSTD::swap(__temp, *__p);
|
2012-07-30 09:40:57 +08:00
|
|
|
*__p = __w;
|
|
|
|
__m.unlock();
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-19 01:50:13 +08:00
|
|
|
_VSTD::swap(__temp, *__v);
|
2012-07-30 09:40:57 +08:00
|
|
|
*__v = *__p;
|
|
|
|
__m.unlock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
bool
|
|
|
|
atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
|
|
|
|
{
|
|
|
|
return atomic_compare_exchange_strong(__p, __v, __w);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
bool
|
|
|
|
atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
|
|
|
|
shared_ptr<_Tp> __w, memory_order, memory_order)
|
|
|
|
{
|
|
|
|
return atomic_compare_exchange_strong(__p, __v, __w);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
|
2012-07-30 09:40:57 +08:00
|
|
|
bool
|
|
|
|
atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
|
|
|
|
shared_ptr<_Tp> __w, memory_order, memory_order)
|
|
|
|
{
|
|
|
|
return atomic_compare_exchange_weak(__p, __v, __w);
|
|
|
|
}
|
|
|
|
|
2016-06-18 10:12:53 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
|
2012-07-30 09:40:57 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
//enum class
|
2017-01-05 09:15:42 +08:00
|
|
|
#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
|
|
|
|
# ifndef _LIBCPP_CXX03_LANG
|
|
|
|
enum class pointer_safety : unsigned char {
|
|
|
|
relaxed,
|
|
|
|
preferred,
|
|
|
|
strict
|
|
|
|
};
|
|
|
|
# endif
|
|
|
|
#else
|
2013-03-07 07:30:19 +08:00
|
|
|
struct _LIBCPP_TYPE_VIS pointer_safety
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2012-10-31 03:06:59 +08:00
|
|
|
enum __lx
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
relaxed,
|
|
|
|
preferred,
|
|
|
|
strict
|
|
|
|
};
|
|
|
|
|
2012-10-31 03:06:59 +08:00
|
|
|
__lx __v_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-05 09:28:40 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pointer_safety() : __v_() {}
|
|
|
|
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-10-31 03:06:59 +08:00
|
|
|
pointer_safety(__lx __v) : __v_(__v) {}
|
2010-09-23 00:48:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
operator int() const {return __v_;}
|
|
|
|
};
|
2017-01-05 09:15:42 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
|
2018-08-01 10:08:59 +08:00
|
|
|
defined(_LIBCPP_BUILDING_LIBRARY)
|
2017-01-05 09:15:42 +08:00
|
|
|
_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
|
|
|
|
#else
|
|
|
|
// This function is only offered in C++03 under ABI v1.
|
|
|
|
# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
pointer_safety get_pointer_safety() _NOEXCEPT {
|
|
|
|
return pointer_safety::relaxed;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
|
|
|
|
_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
|
|
|
|
_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
|
|
|
|
_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-08-22 08:02:43 +08:00
|
|
|
_Tp*
|
2010-05-12 03:42:16 +08:00
|
|
|
undeclare_reachable(_Tp* __p)
|
|
|
|
{
|
|
|
|
return static_cast<_Tp*>(__undeclare_reachable(__p));
|
|
|
|
}
|
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2015-07-14 04:04:56 +08:00
|
|
|
// --- Helper for container swap --
|
|
|
|
template <typename _Alloc>
|
2016-04-22 06:54:21 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2015-07-14 04:04:56 +08:00
|
|
|
void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
|
|
|
|
#if _LIBCPP_STD_VER >= 14
|
|
|
|
_NOEXCEPT
|
|
|
|
#else
|
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
|
|
|
|
#endif
|
|
|
|
{
|
2017-08-20 18:38:55 +08:00
|
|
|
__swap_allocator(__a1, __a2,
|
2015-07-14 04:04:56 +08:00
|
|
|
integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Alloc>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
|
|
|
|
#if _LIBCPP_STD_VER >= 14
|
|
|
|
_NOEXCEPT
|
|
|
|
#else
|
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
using _VSTD::swap;
|
|
|
|
swap(__a1, __a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Alloc>
|
2016-04-22 06:54:21 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2015-07-14 04:04:56 +08:00
|
|
|
void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
|
|
|
|
|
2015-08-19 03:51:37 +08:00
|
|
|
template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
|
2017-08-20 18:38:55 +08:00
|
|
|
struct __noexcept_move_assign_container : public integral_constant<bool,
|
2015-08-19 02:57:00 +08:00
|
|
|
_Traits::propagate_on_container_move_assignment::value
|
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
|| _Traits::is_always_equal::value
|
|
|
|
#else
|
|
|
|
&& is_nothrow_move_assignable<_Alloc>::value
|
|
|
|
#endif
|
|
|
|
> {};
|
2015-07-14 04:04:56 +08:00
|
|
|
|
2016-07-12 05:38:08 +08:00
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
struct __temp_value {
|
|
|
|
typedef allocator_traits<_Alloc> _Traits;
|
2017-08-20 18:38:55 +08:00
|
|
|
|
2019-01-16 09:51:12 +08:00
|
|
|
typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
|
2016-07-12 05:38:08 +08:00
|
|
|
_Alloc &__a;
|
|
|
|
|
|
|
|
_Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
|
|
|
|
_Tp & get() { return *__addr(); }
|
2017-08-20 18:38:55 +08:00
|
|
|
|
2016-07-12 05:38:08 +08:00
|
|
|
template<class... _Args>
|
2018-08-16 01:49:30 +08:00
|
|
|
_LIBCPP_NO_CFI
|
|
|
|
__temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
|
|
|
|
_Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
|
|
|
|
_VSTD::forward<_Args>(__args)...);
|
|
|
|
}
|
2017-08-20 18:38:55 +08:00
|
|
|
|
2016-07-12 05:38:08 +08:00
|
|
|
~__temp_value() { _Traits::destroy(__a, __addr()); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-07-03 02:41:15 +08:00
|
|
|
template<typename _Alloc, typename = void, typename = void>
|
2018-01-12 03:36:22 +08:00
|
|
|
struct __is_allocator : false_type {};
|
|
|
|
|
|
|
|
template<typename _Alloc>
|
|
|
|
struct __is_allocator<_Alloc,
|
2018-07-03 02:41:15 +08:00
|
|
|
typename __void_t<typename _Alloc::value_type>::type,
|
|
|
|
typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
|
|
|
|
>
|
2018-01-12 03:36:22 +08:00
|
|
|
: true_type {};
|
|
|
|
|
2019-06-08 09:31:19 +08:00
|
|
|
// __builtin_new_allocator -- A non-templated helper for allocating and
|
|
|
|
// deallocating memory using __builtin_operator_new and
|
|
|
|
// __builtin_operator_delete. It should be used in preference to
|
|
|
|
// `std::allocator<T>` to avoid additional instantiations.
|
|
|
|
struct __builtin_new_allocator {
|
|
|
|
struct __builtin_new_deleter {
|
|
|
|
typedef void* pointer_type;
|
|
|
|
|
|
|
|
_LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
|
|
|
|
: __size_(__size), __align_(__align) {}
|
|
|
|
|
|
|
|
void operator()(void* p) const _NOEXCEPT {
|
|
|
|
std::__libcpp_deallocate(p, __size_, __align_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t __size_;
|
|
|
|
size_t __align_;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
|
|
|
|
|
|
|
|
static __holder_t __allocate_bytes(size_t __s, size_t __align) {
|
|
|
|
return __holder_t(std::__libcpp_allocate(__s, __align),
|
|
|
|
__builtin_new_deleter(__s, __align));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __deallocate_bytes(void* __p, size_t __s,
|
|
|
|
size_t __align) _NOEXCEPT {
|
|
|
|
std::__libcpp_deallocate(__p, __s, __align);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
_LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
|
|
|
|
static __holder_t __allocate_type(size_t __n) {
|
|
|
|
return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
_LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
|
|
|
|
static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
|
|
|
|
__deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2019-08-06 02:29:14 +08:00
|
|
|
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
|
2019-08-07 05:11:24 +08:00
|
|
|
# include <__pstl_memory>
|
2019-08-06 02:29:14 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif // _LIBCPP_MEMORY
|