1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 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 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_SCOPED_ALLOCATOR 11#define _LIBCPP_SCOPED_ALLOCATOR 12 13/* 14 scoped_allocator synopsis 15 16namespace std 17{ 18 19template <class OuterAlloc, class... InnerAllocs> 20class scoped_allocator_adaptor : public OuterAlloc 21{ 22 typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only 23 scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only 24public: 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; 40 typedef see below is_always_equal; 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, 52 const InnerAllocs&... innerAllocs) noexcept; 53 scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept; 54 scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept; 55 template <class OuterA2> 56 scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept; 57 template <class OuterA2> 58 scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept; 59 60 scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default; 61 scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; 62 ~scoped_allocator_adaptor(); 63 64 inner_allocator_type& inner_allocator() noexcept; 65 const inner_allocator_type& inner_allocator() const noexcept; 66 67 outer_allocator_type& outer_allocator() noexcept; 68 const outer_allocator_type& outer_allocator() const noexcept; 69 70 pointer allocate(size_type n); // [[nodiscard]] in C++20 71 pointer allocate(size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 72 void deallocate(pointer p, size_type n) noexcept; 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 89 template <class T> void destroy(T* p) noexcept; 90 91 scoped_allocator_adaptor select_on_container_copy_construction() const noexcept; 92}; 93 94template<class OuterAlloc, class... InnerAllocs> 95 scoped_allocator_adaptor(OuterAlloc, InnerAllocs...) 96 -> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>; 97 98template <class OuterA1, class OuterA2, class... InnerAllocs> 99 bool 100 operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, 101 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; 102 103template <class OuterA1, class OuterA2, class... InnerAllocs> 104 bool 105 operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, 106 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; // removed in C++20 107 108} // std 109 110*/ 111 112#include <__config> 113#include <__memory/allocator_traits.h> 114#include <__memory/uses_allocator_construction.h> 115#include <__type_traits/common_type.h> 116#include <__type_traits/enable_if.h> 117#include <__type_traits/integral_constant.h> 118#include <__type_traits/is_constructible.h> 119#include <__type_traits/remove_reference.h> 120#include <__utility/declval.h> 121#include <__utility/forward.h> 122#include <__utility/move.h> 123#include <__utility/pair.h> 124#include <__utility/piecewise_construct.h> 125#include <tuple> 126#include <version> 127 128#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 129# pragma GCC system_header 130#endif 131 132_LIBCPP_PUSH_MACROS 133#include <__undef_macros> 134 135_LIBCPP_BEGIN_NAMESPACE_STD 136 137#if !defined(_LIBCPP_CXX03_LANG) 138 139// scoped_allocator_adaptor 140 141template <class... _Allocs> 142class scoped_allocator_adaptor; 143 144template <class... _Allocs> 145struct __get_poc_copy_assignment; 146 147template <class _A0> 148struct __get_poc_copy_assignment<_A0> { 149 static const bool value = allocator_traits<_A0>::propagate_on_container_copy_assignment::value; 150}; 151 152template <class _A0, class... _Allocs> 153struct __get_poc_copy_assignment<_A0, _Allocs...> { 154 static const bool value = allocator_traits<_A0>::propagate_on_container_copy_assignment::value || 155 __get_poc_copy_assignment<_Allocs...>::value; 156}; 157 158template <class... _Allocs> 159struct __get_poc_move_assignment; 160 161template <class _A0> 162struct __get_poc_move_assignment<_A0> { 163 static const bool value = allocator_traits<_A0>::propagate_on_container_move_assignment::value; 164}; 165 166template <class _A0, class... _Allocs> 167struct __get_poc_move_assignment<_A0, _Allocs...> { 168 static const bool value = allocator_traits<_A0>::propagate_on_container_move_assignment::value || 169 __get_poc_move_assignment<_Allocs...>::value; 170}; 171 172template <class... _Allocs> 173struct __get_poc_swap; 174 175template <class _A0> 176struct __get_poc_swap<_A0> { 177 static const bool value = allocator_traits<_A0>::propagate_on_container_swap::value; 178}; 179 180template <class _A0, class... _Allocs> 181struct __get_poc_swap<_A0, _Allocs...> { 182 static const bool value = 183 allocator_traits<_A0>::propagate_on_container_swap::value || __get_poc_swap<_Allocs...>::value; 184}; 185 186template <class... _Allocs> 187struct __get_is_always_equal; 188 189template <class _A0> 190struct __get_is_always_equal<_A0> { 191 static const bool value = allocator_traits<_A0>::is_always_equal::value; 192}; 193 194template <class _A0, class... _Allocs> 195struct __get_is_always_equal<_A0, _Allocs...> { 196 static const bool value = allocator_traits<_A0>::is_always_equal::value && __get_is_always_equal<_Allocs...>::value; 197}; 198 199template <class... _Allocs> 200class __scoped_allocator_storage; 201 202template <class _OuterAlloc, class... _InnerAllocs> 203class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> : public _OuterAlloc { 204 typedef _OuterAlloc outer_allocator_type; 205 206protected: 207 typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type; 208 209private: 210 inner_allocator_type __inner_; 211 212protected: 213 _LIBCPP_HIDE_FROM_ABI __scoped_allocator_storage() _NOEXCEPT {} 214 215 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 216 _LIBCPP_HIDE_FROM_ABI 217 __scoped_allocator_storage(_OuterA2&& __outer_alloc, const _InnerAllocs&... __inner_allocs) _NOEXCEPT 218 : outer_allocator_type(std::forward<_OuterA2>(__outer_alloc)), 219 __inner_(__inner_allocs...) {} 220 221 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, const _OuterA2&>::value, int> = 0> 222 _LIBCPP_HIDE_FROM_ABI 223 __scoped_allocator_storage(const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT 224 : outer_allocator_type(__other.outer_allocator()), 225 __inner_(__other.inner_allocator()) {} 226 227 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 228 _LIBCPP_HIDE_FROM_ABI 229 __scoped_allocator_storage(__scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT 230 : outer_allocator_type(std::move(__other.outer_allocator())), 231 __inner_(std::move(__other.inner_allocator())) {} 232 233 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 234 _LIBCPP_HIDE_FROM_ABI __scoped_allocator_storage(_OuterA2&& __o, const inner_allocator_type& __i) _NOEXCEPT 235 : outer_allocator_type(std::forward<_OuterA2>(__o)), 236 __inner_(__i) {} 237 238 _LIBCPP_HIDE_FROM_ABI inner_allocator_type& inner_allocator() _NOEXCEPT { return __inner_; } 239 _LIBCPP_HIDE_FROM_ABI const inner_allocator_type& inner_allocator() const _NOEXCEPT { return __inner_; } 240 241 _LIBCPP_HIDE_FROM_ABI outer_allocator_type& outer_allocator() _NOEXCEPT { 242 return static_cast<outer_allocator_type&>(*this); 243 } 244 _LIBCPP_HIDE_FROM_ABI const outer_allocator_type& outer_allocator() const _NOEXCEPT { 245 return static_cast<const outer_allocator_type&>(*this); 246 } 247 248 scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> _LIBCPP_HIDE_FROM_ABI 249 select_on_container_copy_construction() const _NOEXCEPT { 250 return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>( 251 allocator_traits<outer_allocator_type>::select_on_container_copy_construction(outer_allocator()), 252 allocator_traits<inner_allocator_type>::select_on_container_copy_construction(inner_allocator())); 253 } 254 255 template <class...> 256 friend class __scoped_allocator_storage; 257}; 258 259template <class _OuterAlloc> 260class __scoped_allocator_storage<_OuterAlloc> : public _OuterAlloc { 261 typedef _OuterAlloc outer_allocator_type; 262 263protected: 264 typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type; 265 266 _LIBCPP_HIDE_FROM_ABI __scoped_allocator_storage() _NOEXCEPT {} 267 268 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 269 _LIBCPP_HIDE_FROM_ABI __scoped_allocator_storage(_OuterA2&& __outer_alloc) _NOEXCEPT 270 : outer_allocator_type(std::forward<_OuterA2>(__outer_alloc)) {} 271 272 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, const _OuterA2&>::value, int> = 0> 273 _LIBCPP_HIDE_FROM_ABI __scoped_allocator_storage(const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT 274 : outer_allocator_type(__other.outer_allocator()) {} 275 276 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 277 _LIBCPP_HIDE_FROM_ABI __scoped_allocator_storage(__scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT 278 : outer_allocator_type(std::move(__other.outer_allocator())) {} 279 280 _LIBCPP_HIDE_FROM_ABI inner_allocator_type& inner_allocator() _NOEXCEPT { 281 return static_cast<inner_allocator_type&>(*this); 282 } 283 _LIBCPP_HIDE_FROM_ABI const inner_allocator_type& inner_allocator() const _NOEXCEPT { 284 return static_cast<const inner_allocator_type&>(*this); 285 } 286 287 _LIBCPP_HIDE_FROM_ABI outer_allocator_type& outer_allocator() _NOEXCEPT { 288 return static_cast<outer_allocator_type&>(*this); 289 } 290 _LIBCPP_HIDE_FROM_ABI const outer_allocator_type& outer_allocator() const _NOEXCEPT { 291 return static_cast<const outer_allocator_type&>(*this); 292 } 293 294 _LIBCPP_HIDE_FROM_ABI scoped_allocator_adaptor<outer_allocator_type> 295 select_on_container_copy_construction() const _NOEXCEPT { 296 return scoped_allocator_adaptor<outer_allocator_type>( 297 allocator_traits<outer_allocator_type>::select_on_container_copy_construction(outer_allocator())); 298 } 299 300 __scoped_allocator_storage(const outer_allocator_type& __o, const inner_allocator_type& __i) _NOEXCEPT; 301 302 template <class...> 303 friend class __scoped_allocator_storage; 304}; 305 306// __outermost 307 308template <class _Alloc> 309decltype(std::declval<_Alloc>().outer_allocator(), true_type()) __has_outer_allocator_test(_Alloc&& __a); 310 311template <class _Alloc> 312false_type __has_outer_allocator_test(const volatile _Alloc& __a); 313 314template <class _Alloc> 315struct __has_outer_allocator 316 : public common_type< decltype(std::__has_outer_allocator_test(std::declval<_Alloc&>()))>::type {}; 317 318template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value> 319struct __outermost { 320 typedef _Alloc type; 321 _LIBCPP_HIDE_FROM_ABI type& operator()(type& __a) const _NOEXCEPT { return __a; } 322}; 323 324template <class _Alloc> 325struct __outermost<_Alloc, true> { 326 typedef __libcpp_remove_reference_t< decltype(std::declval<_Alloc>().outer_allocator()) > _OuterAlloc; 327 typedef typename __outermost<_OuterAlloc>::type type; 328 _LIBCPP_HIDE_FROM_ABI type& operator()(_Alloc& __a) const _NOEXCEPT { 329 return __outermost<_OuterAlloc>()(__a.outer_allocator()); 330 } 331}; 332 333template <class _OuterAlloc, class... _InnerAllocs> 334class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...> 335 : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> { 336 typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> _Base; 337 typedef allocator_traits<_OuterAlloc> _OuterTraits; 338 339public: 340 typedef _OuterAlloc outer_allocator_type; 341 typedef typename _Base::inner_allocator_type inner_allocator_type; 342 typedef typename _OuterTraits::size_type size_type; 343 typedef typename _OuterTraits::difference_type difference_type; 344 typedef typename _OuterTraits::pointer pointer; 345 typedef typename _OuterTraits::const_pointer const_pointer; 346 typedef typename _OuterTraits::void_pointer void_pointer; 347 typedef typename _OuterTraits::const_void_pointer const_void_pointer; 348 349 typedef integral_constant< bool, __get_poc_copy_assignment<outer_allocator_type, _InnerAllocs...>::value > 350 propagate_on_container_copy_assignment; 351 typedef integral_constant< bool, __get_poc_move_assignment<outer_allocator_type, _InnerAllocs...>::value > 352 propagate_on_container_move_assignment; 353 typedef integral_constant< bool, __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value > 354 propagate_on_container_swap; 355 typedef integral_constant< bool, __get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value > 356 is_always_equal; 357 358 template <class _Tp> 359 struct rebind { 360 typedef scoped_allocator_adaptor< typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs... > other; 361 }; 362 363 _LIBCPP_HIDE_FROM_ABI scoped_allocator_adaptor() _NOEXCEPT {} 364 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 365 _LIBCPP_HIDE_FROM_ABI 366 scoped_allocator_adaptor(_OuterA2&& __outer_alloc, const _InnerAllocs&... __inner_allocs) _NOEXCEPT 367 : _Base(std::forward<_OuterA2>(__outer_alloc), __inner_allocs...) {} 368 // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default; 369 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, const _OuterA2&>::value, int> = 0> 370 _LIBCPP_HIDE_FROM_ABI 371 scoped_allocator_adaptor(const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT 372 : _Base(__other) {} 373 template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0> 374 _LIBCPP_HIDE_FROM_ABI 375 scoped_allocator_adaptor(scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT 376 : _Base(std::move(__other)) {} 377 378 // scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default; 379 // scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; 380 // ~scoped_allocator_adaptor() = default; 381 382 _LIBCPP_HIDE_FROM_ABI inner_allocator_type& inner_allocator() _NOEXCEPT { return _Base::inner_allocator(); } 383 _LIBCPP_HIDE_FROM_ABI const inner_allocator_type& inner_allocator() const _NOEXCEPT { 384 return _Base::inner_allocator(); 385 } 386 387 _LIBCPP_HIDE_FROM_ABI outer_allocator_type& outer_allocator() _NOEXCEPT { return _Base::outer_allocator(); } 388 _LIBCPP_HIDE_FROM_ABI const outer_allocator_type& outer_allocator() const _NOEXCEPT { 389 return _Base::outer_allocator(); 390 } 391 392 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n) { 393 return allocator_traits<outer_allocator_type>::allocate(outer_allocator(), __n); 394 } 395 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n, const_void_pointer __hint) { 396 return allocator_traits<outer_allocator_type>::allocate(outer_allocator(), __n, __hint); 397 } 398 399 _LIBCPP_HIDE_FROM_ABI void deallocate(pointer __p, size_type __n) _NOEXCEPT { 400 allocator_traits<outer_allocator_type>::deallocate(outer_allocator(), __p, __n); 401 } 402 403 _LIBCPP_HIDE_FROM_ABI size_type max_size() const { 404 return allocator_traits<outer_allocator_type>::max_size(outer_allocator()); 405 } 406 407# if _LIBCPP_STD_VER >= 20 408 template <class _Type, class... _Args> 409 _LIBCPP_HIDE_FROM_ABI void construct(_Type* __ptr, _Args&&... __args) { 410 using _OM = __outermost<outer_allocator_type>; 411 std::apply( 412 [__ptr, this](auto&&... __newargs) { 413 allocator_traits<typename _OM::type>::construct( 414 _OM()(outer_allocator()), __ptr, std::forward<decltype(__newargs)>(__newargs)...); 415 }, 416 std::uses_allocator_construction_args<_Type>(inner_allocator(), std::forward<_Args>(__args)...)); 417 } 418# else 419 template <class _Tp, class... _Args> 420 _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Args&&... __args) { 421 __construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), __p, std::forward<_Args>(__args)...); 422 } 423 424 template <class _T1, class _T2, class... _Args1, class... _Args2> 425 _LIBCPP_HIDE_FROM_ABI void 426 construct(pair<_T1, _T2>* __p, piecewise_construct_t, tuple<_Args1...> __x, tuple<_Args2...> __y) { 427 typedef __outermost<outer_allocator_type> _OM; 428 allocator_traits<typename _OM::type>::construct( 429 _OM()(outer_allocator()), 430 __p, 431 piecewise_construct, 432 __transform_tuple(typename __uses_alloc_ctor< _T1, inner_allocator_type&, _Args1... >::type(), 433 std::move(__x), 434 typename __make_tuple_indices<sizeof...(_Args1)>::type{}), 435 __transform_tuple(typename __uses_alloc_ctor< _T2, inner_allocator_type&, _Args2... >::type(), 436 std::move(__y), 437 typename __make_tuple_indices<sizeof...(_Args2)>::type{})); 438 } 439 440 template <class _T1, class _T2> 441 _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p) { 442 construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); 443 } 444 445 template <class _T1, class _T2, class _Up, class _Vp> 446 _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) { 447 construct(__p, 448 piecewise_construct, 449 std::forward_as_tuple(std::forward<_Up>(__x)), 450 std::forward_as_tuple(std::forward<_Vp>(__y))); 451 } 452 453 template <class _T1, class _T2, class _Up, class _Vp> 454 _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) { 455 construct(__p, piecewise_construct, std::forward_as_tuple(__x.first), std::forward_as_tuple(__x.second)); 456 } 457 458 template <class _T1, class _T2, class _Up, class _Vp> 459 _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) { 460 construct(__p, 461 piecewise_construct, 462 std::forward_as_tuple(std::forward<_Up>(__x.first)), 463 std::forward_as_tuple(std::forward<_Vp>(__x.second))); 464 } 465# endif 466 467 template <class _Tp> 468 _LIBCPP_HIDE_FROM_ABI void destroy(_Tp* __p) { 469 typedef __outermost<outer_allocator_type> _OM; 470 allocator_traits<typename _OM::type>::destroy(_OM()(outer_allocator()), __p); 471 } 472 473 _LIBCPP_HIDE_FROM_ABI scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT { 474 return _Base::select_on_container_copy_construction(); 475 } 476 477private: 478 _LIBCPP_HIDE_FROM_ABI explicit scoped_allocator_adaptor( 479 outer_allocator_type&& __o, inner_allocator_type&& __i) _NOEXCEPT : _Base(std::move(__o), std::move(__i)) {} 480 481 template <class _Tp, class... _Args> 482 _LIBCPP_HIDE_FROM_ABI void __construct(integral_constant<int, 0>, _Tp* __p, _Args&&... __args) { 483 typedef __outermost<outer_allocator_type> _OM; 484 allocator_traits<typename _OM::type>::construct(_OM()(outer_allocator()), __p, std::forward<_Args>(__args)...); 485 } 486 487 template <class _Tp, class... _Args> 488 _LIBCPP_HIDE_FROM_ABI void __construct(integral_constant<int, 1>, _Tp* __p, _Args&&... __args) { 489 typedef __outermost<outer_allocator_type> _OM; 490 allocator_traits<typename _OM::type>::construct( 491 _OM()(outer_allocator()), __p, allocator_arg, inner_allocator(), std::forward<_Args>(__args)...); 492 } 493 494 template <class _Tp, class... _Args> 495 _LIBCPP_HIDE_FROM_ABI void __construct(integral_constant<int, 2>, _Tp* __p, _Args&&... __args) { 496 typedef __outermost<outer_allocator_type> _OM; 497 allocator_traits<typename _OM::type>::construct( 498 _OM()(outer_allocator()), __p, std::forward<_Args>(__args)..., inner_allocator()); 499 } 500 501 template <class... _Args, size_t... _Idx> 502 _LIBCPP_HIDE_FROM_ABI tuple<_Args&&...> 503 __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, __tuple_indices<_Idx...>) { 504 return std::forward_as_tuple(std::get<_Idx>(std::move(__t))...); 505 } 506 507 template <class... _Args, size_t... _Idx> 508 _LIBCPP_HIDE_FROM_ABI tuple<allocator_arg_t, inner_allocator_type&, _Args&&...> 509 __transform_tuple(integral_constant<int, 1>, tuple<_Args...>&& __t, __tuple_indices<_Idx...>) { 510 using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>; 511 return _Tup(allocator_arg, inner_allocator(), std::get<_Idx>(std::move(__t))...); 512 } 513 514 template <class... _Args, size_t... _Idx> 515 _LIBCPP_HIDE_FROM_ABI tuple<_Args&&..., inner_allocator_type&> 516 __transform_tuple(integral_constant<int, 2>, tuple<_Args...>&& __t, __tuple_indices<_Idx...>) { 517 using _Tup = tuple<_Args&&..., inner_allocator_type&>; 518 return _Tup(std::get<_Idx>(std::move(__t))..., inner_allocator()); 519 } 520 521 template <class...> 522 friend class __scoped_allocator_storage; 523}; 524 525# if _LIBCPP_STD_VER >= 17 526template <class _OuterAlloc, class... _InnerAllocs> 527scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...) -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>; 528# endif 529 530template <class _OuterA1, class _OuterA2> 531inline _LIBCPP_HIDE_FROM_ABI bool 532operator==(const scoped_allocator_adaptor<_OuterA1>& __a, const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT { 533 return __a.outer_allocator() == __b.outer_allocator(); 534} 535 536template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs> 537inline _LIBCPP_HIDE_FROM_ABI bool 538operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a, 539 const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT { 540 return __a.outer_allocator() == __b.outer_allocator() && __a.inner_allocator() == __b.inner_allocator(); 541} 542 543# if _LIBCPP_STD_VER <= 17 544 545template <class _OuterA1, class _OuterA2, class... _InnerAllocs> 546inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a, 547 const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT { 548 return !(__a == __b); 549} 550 551# endif // _LIBCPP_STD_VER <= 17 552 553#endif // !defined(_LIBCPP_CXX03_LANG) 554 555_LIBCPP_END_NAMESPACE_STD 556 557_LIBCPP_POP_MACROS 558 559#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 560# include <atomic> 561# include <climits> 562# include <concepts> 563# include <cstring> 564# include <ctime> 565# include <iterator> 566# include <memory> 567# include <ratio> 568# include <stdexcept> 569# include <type_traits> 570# include <variant> 571#endif 572 573#endif // _LIBCPP_SCOPED_ALLOCATOR 574