Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | eb8650a | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_SCOPED_ALLOCATOR |
| 11 | #define _LIBCPP_SCOPED_ALLOCATOR |
| 12 | |
| 13 | /* |
| 14 | scoped_allocator synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class OuterAlloc, class... InnerAllocs> |
| 20 | class scoped_allocator_adaptor : public OuterAlloc |
| 21 | { |
| 22 | typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 23 | scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 24 | public: |
| 25 | |
| 26 | typedef OuterAlloc outer_allocator_type; |
| 27 | typedef see below inner_allocator_type; |
| 28 | |
| 29 | typedef typename OuterTraits::value_type value_type; |
| 30 | typedef typename OuterTraits::size_type size_type; |
| 31 | typedef typename OuterTraits::difference_type difference_type; |
| 32 | typedef typename OuterTraits::pointer pointer; |
| 33 | typedef typename OuterTraits::const_pointer const_pointer; |
| 34 | typedef typename OuterTraits::void_pointer void_pointer; |
| 35 | typedef typename OuterTraits::const_void_pointer const_void_pointer; |
| 36 | |
| 37 | typedef see below propagate_on_container_copy_assignment; |
| 38 | typedef see below propagate_on_container_move_assignment; |
| 39 | typedef see below propagate_on_container_swap; |
Marshall Clow | 31a4731 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 40 | typedef see below is_always_equal; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 41 | |
| 42 | template <class Tp> |
| 43 | struct rebind |
| 44 | { |
| 45 | typedef scoped_allocator_adaptor< |
| 46 | OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other; |
| 47 | }; |
| 48 | |
| 49 | scoped_allocator_adaptor(); |
| 50 | template <class OuterA2> |
| 51 | scoped_allocator_adaptor(OuterA2&& outerAlloc, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 52 | const InnerAllocs&... innerAllocs) noexcept; |
| 53 | scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept; |
| 54 | scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 55 | template <class OuterA2> |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 56 | scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 57 | template <class OuterA2> |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 58 | scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 59 | |
Marshall Clow | cd5215d | 2015-10-25 19:52:47 +0000 | [diff] [blame] | 60 | scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default; |
| 61 | scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 62 | ~scoped_allocator_adaptor(); |
| 63 | |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 64 | inner_allocator_type& inner_allocator() noexcept; |
| 65 | const inner_allocator_type& inner_allocator() const noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 66 | |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 67 | outer_allocator_type& outer_allocator() noexcept; |
| 68 | const outer_allocator_type& outer_allocator() const noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 69 | |
Marshall Clow | 3fddff5 | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 70 | pointer allocate(size_type n); // [[nodiscard]] in C++20 |
| 71 | pointer allocate(size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 72 | void deallocate(pointer p, size_type n) noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 73 | |
| 74 | size_type max_size() const; |
| 75 | template <class T, class... Args> void construct(T* p, Args&& args); |
| 76 | template <class T1, class T2, class... Args1, class... Args2> |
| 77 | void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x, |
| 78 | tuple<Args2...> y); |
| 79 | template <class T1, class T2> |
| 80 | void construct(pair<T1, T2>* p); |
| 81 | template <class T1, class T2, class U, class V> |
| 82 | void construct(pair<T1, T2>* p, U&& x, V&& y); |
| 83 | template <class T1, class T2, class U, class V> |
| 84 | void construct(pair<T1, T2>* p, const pair<U, V>& x); |
| 85 | template <class T1, class T2, class U, class V> |
| 86 | void construct(pair<T1, T2>* p, pair<U, V>&& x); |
| 87 | template <class T> void destroy(T* p); |
| 88 | |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 89 | template <class T> void destroy(T* p) noexcept; |
| 90 | |
| 91 | scoped_allocator_adaptor select_on_container_copy_construction() const noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Konstantin Varlamov | f9f97ca | 2021-10-28 00:36:19 -0700 | [diff] [blame] | 94 | template<class OuterAlloc, class... InnerAllocs> |
| 95 | scoped_allocator_adaptor(OuterAlloc, InnerAllocs...) |
| 96 | -> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>; |
| 97 | |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 98 | template <class OuterA1, class OuterA2, class... InnerAllocs> |
| 99 | bool |
| 100 | operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 101 | const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 102 | |
| 103 | template <class OuterA1, class OuterA2, class... InnerAllocs> |
| 104 | bool |
| 105 | operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 106 | const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 107 | |
| 108 | } // std |
| 109 | |
| 110 | */ |
| 111 | |
| 112 | #include <__config> |
Christopher Di Bella | 6adbc83 | 2021-06-05 02:47:47 +0000 | [diff] [blame] | 113 | #include <__utility/forward.h> |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 114 | #include <memory> |
Marshall Clow | f56972e | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 115 | #include <version> |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 116 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 117 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 118 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 119 | #endif |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 120 | |
| 121 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 122 | |
Eric Fiselier | 54613ab | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 123 | #if !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 124 | |
| 125 | // scoped_allocator_adaptor |
| 126 | |
| 127 | template <class ..._Allocs> |
| 128 | class scoped_allocator_adaptor; |
| 129 | |
| 130 | template <class ..._Allocs> struct __get_poc_copy_assignment; |
| 131 | |
| 132 | template <class _A0> |
| 133 | struct __get_poc_copy_assignment<_A0> |
| 134 | { |
| 135 | static const bool value = allocator_traits<_A0>:: |
| 136 | propagate_on_container_copy_assignment::value; |
| 137 | }; |
| 138 | |
| 139 | template <class _A0, class ..._Allocs> |
| 140 | struct __get_poc_copy_assignment<_A0, _Allocs...> |
| 141 | { |
| 142 | static const bool value = |
| 143 | allocator_traits<_A0>::propagate_on_container_copy_assignment::value || |
| 144 | __get_poc_copy_assignment<_Allocs...>::value; |
| 145 | }; |
| 146 | |
| 147 | template <class ..._Allocs> struct __get_poc_move_assignment; |
| 148 | |
| 149 | template <class _A0> |
| 150 | struct __get_poc_move_assignment<_A0> |
| 151 | { |
| 152 | static const bool value = allocator_traits<_A0>:: |
| 153 | propagate_on_container_move_assignment::value; |
| 154 | }; |
| 155 | |
| 156 | template <class _A0, class ..._Allocs> |
| 157 | struct __get_poc_move_assignment<_A0, _Allocs...> |
| 158 | { |
| 159 | static const bool value = |
| 160 | allocator_traits<_A0>::propagate_on_container_move_assignment::value || |
| 161 | __get_poc_move_assignment<_Allocs...>::value; |
| 162 | }; |
| 163 | |
| 164 | template <class ..._Allocs> struct __get_poc_swap; |
| 165 | |
| 166 | template <class _A0> |
| 167 | struct __get_poc_swap<_A0> |
| 168 | { |
| 169 | static const bool value = allocator_traits<_A0>:: |
| 170 | propagate_on_container_swap::value; |
| 171 | }; |
| 172 | |
| 173 | template <class _A0, class ..._Allocs> |
| 174 | struct __get_poc_swap<_A0, _Allocs...> |
| 175 | { |
| 176 | static const bool value = |
| 177 | allocator_traits<_A0>::propagate_on_container_swap::value || |
| 178 | __get_poc_swap<_Allocs...>::value; |
| 179 | }; |
| 180 | |
Marshall Clow | 8880c20 | 2015-06-02 21:40:58 +0000 | [diff] [blame] | 181 | template <class ..._Allocs> struct __get_is_always_equal; |
| 182 | |
| 183 | template <class _A0> |
| 184 | struct __get_is_always_equal<_A0> |
| 185 | { |
| 186 | static const bool value = allocator_traits<_A0>::is_always_equal::value; |
| 187 | }; |
| 188 | |
Marshall Clow | 31a4731 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 189 | template <class _A0, class ..._Allocs> |
Marshall Clow | 8880c20 | 2015-06-02 21:40:58 +0000 | [diff] [blame] | 190 | struct __get_is_always_equal<_A0, _Allocs...> |
Marshall Clow | 31a4731 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 191 | { |
| 192 | static const bool value = |
Marshall Clow | 2abfcd5 | 2015-06-03 16:15:55 +0000 | [diff] [blame] | 193 | allocator_traits<_A0>::is_always_equal::value && |
Marshall Clow | 8880c20 | 2015-06-02 21:40:58 +0000 | [diff] [blame] | 194 | __get_is_always_equal<_Allocs...>::value; |
Marshall Clow | 31a4731 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 197 | template <class ..._Allocs> |
| 198 | class __scoped_allocator_storage; |
| 199 | |
| 200 | template <class _OuterAlloc, class... _InnerAllocs> |
| 201 | class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> |
| 202 | : public _OuterAlloc |
| 203 | { |
| 204 | typedef _OuterAlloc outer_allocator_type; |
| 205 | protected: |
| 206 | typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type; |
| 207 | |
| 208 | private: |
| 209 | inner_allocator_type __inner_; |
| 210 | |
| 211 | protected: |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 212 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 213 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 214 | __scoped_allocator_storage() _NOEXCEPT {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 215 | |
| 216 | template <class _OuterA2, |
| 217 | class = typename enable_if< |
| 218 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 219 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 220 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 221 | __scoped_allocator_storage(_OuterA2&& __outerAlloc, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 222 | const _InnerAllocs& ...__innerAllocs) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 223 | : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)), |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 224 | __inner_(__innerAllocs...) {} |
| 225 | |
| 226 | template <class _OuterA2, |
| 227 | class = typename enable_if< |
| 228 | is_constructible<outer_allocator_type, const _OuterA2&>::value |
| 229 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 230 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 231 | __scoped_allocator_storage( |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 232 | const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 233 | : outer_allocator_type(__other.outer_allocator()), |
| 234 | __inner_(__other.inner_allocator()) {} |
| 235 | |
| 236 | template <class _OuterA2, |
| 237 | class = typename enable_if< |
| 238 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 239 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 240 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 241 | __scoped_allocator_storage( |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 242 | __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 243 | : outer_allocator_type(_VSTD::move(__other.outer_allocator())), |
| 244 | __inner_(_VSTD::move(__other.inner_allocator())) {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 245 | |
| 246 | template <class _OuterA2, |
| 247 | class = typename enable_if< |
| 248 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 249 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 250 | _LIBCPP_INLINE_VISIBILITY |
| 251 | __scoped_allocator_storage(_OuterA2&& __o, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 252 | const inner_allocator_type& __i) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 253 | : outer_allocator_type(_VSTD::forward<_OuterA2>(__o)), |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 254 | __inner_(__i) |
| 255 | { |
| 256 | } |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 257 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 258 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 259 | inner_allocator_type& inner_allocator() _NOEXCEPT {return __inner_;} |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 260 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 261 | const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 262 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 263 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 264 | outer_allocator_type& outer_allocator() _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 265 | {return static_cast<outer_allocator_type&>(*this);} |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 266 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 267 | const outer_allocator_type& outer_allocator() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 268 | {return static_cast<const outer_allocator_type&>(*this);} |
| 269 | |
| 270 | scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 271 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 272 | select_on_container_copy_construction() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 273 | { |
| 274 | return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> |
| 275 | ( |
| 276 | allocator_traits<outer_allocator_type>:: |
| 277 | select_on_container_copy_construction(outer_allocator()), |
| 278 | allocator_traits<inner_allocator_type>:: |
| 279 | select_on_container_copy_construction(inner_allocator()) |
| 280 | ); |
| 281 | } |
| 282 | |
| 283 | template <class...> friend class __scoped_allocator_storage; |
| 284 | }; |
| 285 | |
| 286 | template <class _OuterAlloc> |
| 287 | class __scoped_allocator_storage<_OuterAlloc> |
| 288 | : public _OuterAlloc |
| 289 | { |
| 290 | typedef _OuterAlloc outer_allocator_type; |
| 291 | protected: |
| 292 | typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type; |
| 293 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 294 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 295 | __scoped_allocator_storage() _NOEXCEPT {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 296 | |
| 297 | template <class _OuterA2, |
| 298 | class = typename enable_if< |
| 299 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 300 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 301 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 302 | __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 303 | : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 304 | |
| 305 | template <class _OuterA2, |
| 306 | class = typename enable_if< |
| 307 | is_constructible<outer_allocator_type, const _OuterA2&>::value |
| 308 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 310 | __scoped_allocator_storage( |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 311 | const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 312 | : outer_allocator_type(__other.outer_allocator()) {} |
| 313 | |
| 314 | template <class _OuterA2, |
| 315 | class = typename enable_if< |
| 316 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 317 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 318 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 319 | __scoped_allocator_storage( |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 320 | __scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 321 | : outer_allocator_type(_VSTD::move(__other.outer_allocator())) {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 322 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 323 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 324 | inner_allocator_type& inner_allocator() _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 325 | {return static_cast<inner_allocator_type&>(*this);} |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 327 | const inner_allocator_type& inner_allocator() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 328 | {return static_cast<const inner_allocator_type&>(*this);} |
| 329 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 331 | outer_allocator_type& outer_allocator() _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 332 | {return static_cast<outer_allocator_type&>(*this);} |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 333 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 334 | const outer_allocator_type& outer_allocator() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 335 | {return static_cast<const outer_allocator_type&>(*this);} |
| 336 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 337 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 338 | scoped_allocator_adaptor<outer_allocator_type> |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 339 | select_on_container_copy_construction() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 340 | {return scoped_allocator_adaptor<outer_allocator_type>( |
| 341 | allocator_traits<outer_allocator_type>:: |
| 342 | select_on_container_copy_construction(outer_allocator()) |
| 343 | );} |
| 344 | |
| 345 | __scoped_allocator_storage(const outer_allocator_type& __o, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 346 | const inner_allocator_type& __i) _NOEXCEPT; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 347 | |
| 348 | template <class...> friend class __scoped_allocator_storage; |
| 349 | }; |
| 350 | |
| 351 | // __outermost |
| 352 | |
| 353 | template <class _Alloc> |
| 354 | decltype(declval<_Alloc>().outer_allocator(), true_type()) |
| 355 | __has_outer_allocator_test(_Alloc&& __a); |
| 356 | |
| 357 | template <class _Alloc> |
| 358 | false_type |
| 359 | __has_outer_allocator_test(const volatile _Alloc& __a); |
| 360 | |
| 361 | template <class _Alloc> |
| 362 | struct __has_outer_allocator |
| 363 | : public common_type |
| 364 | < |
| 365 | decltype(__has_outer_allocator_test(declval<_Alloc&>())) |
| 366 | >::type |
| 367 | { |
| 368 | }; |
| 369 | |
| 370 | template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value> |
| 371 | struct __outermost |
| 372 | { |
| 373 | typedef _Alloc type; |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 374 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 375 | type& operator()(type& __a) const _NOEXCEPT {return __a;} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 376 | }; |
| 377 | |
| 378 | template <class _Alloc> |
| 379 | struct __outermost<_Alloc, true> |
| 380 | { |
| 381 | typedef typename remove_reference |
| 382 | < |
Arthur O'Dwyer | ab3fcc5 | 2021-05-10 13:04:16 -0400 | [diff] [blame] | 383 | decltype(declval<_Alloc>().outer_allocator()) |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 384 | >::type _OuterAlloc; |
| 385 | typedef typename __outermost<_OuterAlloc>::type type; |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 386 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 387 | type& operator()(_Alloc& __a) const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 388 | {return __outermost<_OuterAlloc>()(__a.outer_allocator());} |
| 389 | }; |
| 390 | |
| 391 | template <class _OuterAlloc, class... _InnerAllocs> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 392 | class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...> |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 393 | : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> |
| 394 | { |
| 395 | typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base; |
| 396 | typedef allocator_traits<_OuterAlloc> _OuterTraits; |
| 397 | public: |
| 398 | typedef _OuterAlloc outer_allocator_type; |
| 399 | typedef typename base::inner_allocator_type inner_allocator_type; |
| 400 | typedef typename _OuterTraits::size_type size_type; |
| 401 | typedef typename _OuterTraits::difference_type difference_type; |
| 402 | typedef typename _OuterTraits::pointer pointer; |
| 403 | typedef typename _OuterTraits::const_pointer const_pointer; |
| 404 | typedef typename _OuterTraits::void_pointer void_pointer; |
| 405 | typedef typename _OuterTraits::const_void_pointer const_void_pointer; |
| 406 | |
| 407 | typedef integral_constant |
| 408 | < |
| 409 | bool, |
| 410 | __get_poc_copy_assignment<outer_allocator_type, |
| 411 | _InnerAllocs...>::value |
| 412 | > propagate_on_container_copy_assignment; |
| 413 | typedef integral_constant |
| 414 | < |
| 415 | bool, |
| 416 | __get_poc_move_assignment<outer_allocator_type, |
| 417 | _InnerAllocs...>::value |
| 418 | > propagate_on_container_move_assignment; |
| 419 | typedef integral_constant |
| 420 | < |
| 421 | bool, |
| 422 | __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value |
| 423 | > propagate_on_container_swap; |
Marshall Clow | 31a4731 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 424 | typedef integral_constant |
| 425 | < |
| 426 | bool, |
Marshall Clow | 8880c20 | 2015-06-02 21:40:58 +0000 | [diff] [blame] | 427 | __get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value |
Marshall Clow | 31a4731 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 428 | > is_always_equal; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 429 | |
| 430 | template <class _Tp> |
| 431 | struct rebind |
| 432 | { |
| 433 | typedef scoped_allocator_adaptor |
| 434 | < |
| 435 | typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs... |
| 436 | > other; |
| 437 | }; |
| 438 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 439 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 440 | scoped_allocator_adaptor() _NOEXCEPT {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 441 | template <class _OuterA2, |
| 442 | class = typename enable_if< |
| 443 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 444 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 445 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 446 | scoped_allocator_adaptor(_OuterA2&& __outerAlloc, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 447 | const _InnerAllocs& ...__innerAllocs) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 448 | : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 449 | // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default; |
| 450 | template <class _OuterA2, |
| 451 | class = typename enable_if< |
| 452 | is_constructible<outer_allocator_type, const _OuterA2&>::value |
| 453 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 455 | scoped_allocator_adaptor( |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 456 | const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 457 | : base(__other) {} |
| 458 | template <class _OuterA2, |
| 459 | class = typename enable_if< |
| 460 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 461 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 462 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 463 | scoped_allocator_adaptor( |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 464 | scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 465 | : base(_VSTD::move(__other)) {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 466 | |
Marshall Clow | cd5215d | 2015-10-25 19:52:47 +0000 | [diff] [blame] | 467 | // scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default; |
| 468 | // scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 469 | // ~scoped_allocator_adaptor() = default; |
| 470 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 471 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 472 | inner_allocator_type& inner_allocator() _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 473 | {return base::inner_allocator();} |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 474 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 475 | const inner_allocator_type& inner_allocator() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 476 | {return base::inner_allocator();} |
| 477 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 478 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 479 | outer_allocator_type& outer_allocator() _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 480 | {return base::outer_allocator();} |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 481 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 482 | const outer_allocator_type& outer_allocator() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 483 | {return base::outer_allocator();} |
| 484 | |
Marshall Clow | 3fddff5 | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 485 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 486 | pointer allocate(size_type __n) |
| 487 | {return allocator_traits<outer_allocator_type>:: |
| 488 | allocate(outer_allocator(), __n);} |
Marshall Clow | 3fddff5 | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 489 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 490 | pointer allocate(size_type __n, const_void_pointer __hint) |
| 491 | {return allocator_traits<outer_allocator_type>:: |
| 492 | allocate(outer_allocator(), __n, __hint);} |
| 493 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 495 | void deallocate(pointer __p, size_type __n) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 496 | {allocator_traits<outer_allocator_type>:: |
| 497 | deallocate(outer_allocator(), __p, __n);} |
| 498 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 499 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 500 | size_type max_size() const |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 501 | {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 502 | |
| 503 | template <class _Tp, class... _Args> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 504 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 505 | void construct(_Tp* __p, _Args&& ...__args) |
Eric Fiselier | 4ffd08c | 2016-12-14 21:29:29 +0000 | [diff] [blame] | 506 | {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 507 | __p, _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | 4ffd08c | 2016-12-14 21:29:29 +0000 | [diff] [blame] | 508 | |
| 509 | template <class _T1, class _T2, class... _Args1, class... _Args2> |
| 510 | void construct(pair<_T1, _T2>* __p, piecewise_construct_t, |
| 511 | tuple<_Args1...> __x, tuple<_Args2...> __y) |
| 512 | { |
| 513 | typedef __outermost<outer_allocator_type> _OM; |
| 514 | allocator_traits<typename _OM::type>::construct( |
| 515 | _OM()(outer_allocator()), __p, piecewise_construct |
| 516 | , __transform_tuple( |
| 517 | typename __uses_alloc_ctor< |
| 518 | _T1, inner_allocator_type&, _Args1... |
| 519 | >::type() |
| 520 | , _VSTD::move(__x) |
| 521 | , typename __make_tuple_indices<sizeof...(_Args1)>::type{} |
| 522 | ) |
| 523 | , __transform_tuple( |
| 524 | typename __uses_alloc_ctor< |
| 525 | _T2, inner_allocator_type&, _Args2... |
| 526 | >::type() |
| 527 | , _VSTD::move(__y) |
| 528 | , typename __make_tuple_indices<sizeof...(_Args2)>::type{} |
| 529 | ) |
| 530 | ); |
| 531 | } |
| 532 | |
| 533 | template <class _T1, class _T2> |
| 534 | void construct(pair<_T1, _T2>* __p) |
| 535 | { construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); } |
| 536 | |
| 537 | template <class _T1, class _T2, class _Up, class _Vp> |
| 538 | void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) { |
| 539 | construct(__p, piecewise_construct, |
| 540 | _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x)), |
| 541 | _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__y))); |
| 542 | } |
| 543 | |
| 544 | template <class _T1, class _T2, class _Up, class _Vp> |
| 545 | void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) { |
| 546 | construct(__p, piecewise_construct, |
| 547 | _VSTD::forward_as_tuple(__x.first), |
| 548 | _VSTD::forward_as_tuple(__x.second)); |
| 549 | } |
| 550 | |
| 551 | template <class _T1, class _T2, class _Up, class _Vp> |
| 552 | void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) { |
| 553 | construct(__p, piecewise_construct, |
| 554 | _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)), |
| 555 | _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second))); |
| 556 | } |
| 557 | |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 558 | template <class _Tp> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 559 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 560 | void destroy(_Tp* __p) |
| 561 | { |
| 562 | typedef __outermost<outer_allocator_type> _OM; |
| 563 | allocator_traits<typename _OM::type>:: |
| 564 | destroy(_OM()(outer_allocator()), __p); |
| 565 | } |
| 566 | |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 568 | scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 569 | {return base::select_on_container_copy_construction();} |
| 570 | |
| 571 | private: |
| 572 | |
Eric Fiselier | 4ffd08c | 2016-12-14 21:29:29 +0000 | [diff] [blame] | 573 | |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 574 | template <class _OuterA2, |
| 575 | class = typename enable_if< |
| 576 | is_constructible<outer_allocator_type, _OuterA2>::value |
| 577 | >::type> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 579 | scoped_allocator_adaptor(_OuterA2&& __o, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 580 | const inner_allocator_type& __i) _NOEXCEPT |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 581 | : base(_VSTD::forward<_OuterA2>(__o), __i) {} |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 582 | |
| 583 | template <class _Tp, class... _Args> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 585 | void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args) |
| 586 | { |
| 587 | typedef __outermost<outer_allocator_type> _OM; |
| 588 | allocator_traits<typename _OM::type>::construct |
| 589 | ( |
| 590 | _OM()(outer_allocator()), |
| 591 | __p, |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 592 | _VSTD::forward<_Args>(__args)... |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 593 | ); |
| 594 | } |
| 595 | |
| 596 | template <class _Tp, class... _Args> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 598 | void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args) |
| 599 | { |
| 600 | typedef __outermost<outer_allocator_type> _OM; |
| 601 | allocator_traits<typename _OM::type>::construct |
| 602 | ( |
| 603 | _OM()(outer_allocator()), |
Eric Fiselier | 4ffd08c | 2016-12-14 21:29:29 +0000 | [diff] [blame] | 604 | __p, allocator_arg, inner_allocator(), |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 605 | _VSTD::forward<_Args>(__args)... |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 606 | ); |
| 607 | } |
| 608 | |
| 609 | template <class _Tp, class... _Args> |
Howard Hinnant | 53ec0b4 | 2010-09-23 16:27:36 +0000 | [diff] [blame] | 610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 611 | void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args) |
| 612 | { |
| 613 | typedef __outermost<outer_allocator_type> _OM; |
| 614 | allocator_traits<typename _OM::type>::construct |
| 615 | ( |
| 616 | _OM()(outer_allocator()), |
| 617 | __p, |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 618 | _VSTD::forward<_Args>(__args)..., |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 619 | inner_allocator() |
| 620 | ); |
| 621 | } |
| 622 | |
Eric Fiselier | 4ffd08c | 2016-12-14 21:29:29 +0000 | [diff] [blame] | 623 | template <class ..._Args, size_t ..._Idx> |
| 624 | _LIBCPP_INLINE_VISIBILITY |
| 625 | tuple<_Args&&...> |
| 626 | __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, |
| 627 | __tuple_indices<_Idx...>) |
| 628 | { |
| 629 | return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...); |
| 630 | } |
| 631 | |
| 632 | template <class ..._Args, size_t ..._Idx> |
| 633 | _LIBCPP_INLINE_VISIBILITY |
| 634 | tuple<allocator_arg_t, inner_allocator_type&, _Args&&...> |
| 635 | __transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t, |
| 636 | __tuple_indices<_Idx...>) |
| 637 | { |
| 638 | using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>; |
| 639 | return _Tup(allocator_arg, inner_allocator(), |
| 640 | _VSTD::get<_Idx>(_VSTD::move(__t))...); |
| 641 | } |
| 642 | |
| 643 | template <class ..._Args, size_t ..._Idx> |
| 644 | _LIBCPP_INLINE_VISIBILITY |
| 645 | tuple<_Args&&..., inner_allocator_type&> |
| 646 | __transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t, |
| 647 | __tuple_indices<_Idx...>) |
| 648 | { |
| 649 | using _Tup = tuple<_Args&&..., inner_allocator_type&>; |
| 650 | return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., inner_allocator()); |
| 651 | } |
| 652 | |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 653 | template <class...> friend class __scoped_allocator_storage; |
| 654 | }; |
| 655 | |
Konstantin Varlamov | f9f97ca | 2021-10-28 00:36:19 -0700 | [diff] [blame] | 656 | #if _LIBCPP_STD_VER > 14 |
| 657 | template<class _OuterAlloc, class... _InnerAllocs> |
| 658 | scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...) |
| 659 | -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>; |
| 660 | #endif |
| 661 | |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 662 | template <class _OuterA1, class _OuterA2> |
| 663 | inline _LIBCPP_INLINE_VISIBILITY |
| 664 | bool |
| 665 | operator==(const scoped_allocator_adaptor<_OuterA1>& __a, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 666 | const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 667 | { |
| 668 | return __a.outer_allocator() == __b.outer_allocator(); |
| 669 | } |
| 670 | |
Howard Hinnant | dcaa2e9 | 2011-05-17 20:41:18 +0000 | [diff] [blame] | 671 | template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs> |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 672 | inline _LIBCPP_INLINE_VISIBILITY |
| 673 | bool |
Howard Hinnant | dcaa2e9 | 2011-05-17 20:41:18 +0000 | [diff] [blame] | 674 | operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 675 | const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 676 | { |
| 677 | return __a.outer_allocator() == __b.outer_allocator() && |
| 678 | __a.inner_allocator() == __b.inner_allocator(); |
| 679 | } |
| 680 | |
| 681 | template <class _OuterA1, class _OuterA2, class... _InnerAllocs> |
| 682 | inline _LIBCPP_INLINE_VISIBILITY |
| 683 | bool |
| 684 | operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a, |
Howard Hinnant | cfd5278 | 2011-05-28 18:51:12 +0000 | [diff] [blame] | 685 | const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 686 | { |
| 687 | return !(__a == __b); |
| 688 | } |
| 689 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 690 | #endif // !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | 20cc2a4 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 691 | |
| 692 | _LIBCPP_END_NAMESPACE_STD |
| 693 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 694 | #endif // _LIBCPP_SCOPED_ALLOCATOR |