comparison libcxx/include/scoped_allocator @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 5f17cb93ff66
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
1 // -*- C++ -*- 1 // -*- C++ -*-
2 //===-------------------------- scoped_allocator --------------------------===// 2 //===----------------------------------------------------------------------===//
3 // 3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 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. 5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 // 7 //
89 template <class T> void destroy(T* p) noexcept; 89 template <class T> void destroy(T* p) noexcept;
90 90
91 scoped_allocator_adaptor select_on_container_copy_construction() const noexcept; 91 scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
92 }; 92 };
93 93
94 template<class OuterAlloc, class... InnerAllocs>
95 scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)
96 -> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;
97
94 template <class OuterA1, class OuterA2, class... InnerAllocs> 98 template <class OuterA1, class OuterA2, class... InnerAllocs>
95 bool 99 bool
96 operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, 100 operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
97 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; 101 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
98 102
103 107
104 } // std 108 } // std
105 109
106 */ 110 */
107 111
112 #include <__assert> // all public C++ headers provide the assertion handler
108 #include <__config> 113 #include <__config>
114 #include <__memory/allocator_traits.h>
115 #include <__memory/uses_allocator_construction.h>
116 #include <__type_traits/common_type.h>
117 #include <__type_traits/enable_if.h>
118 #include <__type_traits/integral_constant.h>
119 #include <__type_traits/is_constructible.h>
120 #include <__type_traits/remove_reference.h>
109 #include <__utility/forward.h> 121 #include <__utility/forward.h>
110 #include <memory> 122 #include <__utility/move.h>
123 #include <__utility/pair.h>
124 #include <__utility/piecewise_construct.h>
125 #include <tuple>
111 #include <version> 126 #include <version>
112 127
113 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 128 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
114 #pragma GCC system_header 129 # pragma GCC system_header
115 #endif 130 #endif
116 131
117 _LIBCPP_BEGIN_NAMESPACE_STD 132 _LIBCPP_BEGIN_NAMESPACE_STD
118 133
119 #if !defined(_LIBCPP_CXX03_LANG) 134 #if !defined(_LIBCPP_CXX03_LANG)
212 template <class _OuterA2, 227 template <class _OuterA2,
213 class = typename enable_if< 228 class = typename enable_if<
214 is_constructible<outer_allocator_type, _OuterA2>::value 229 is_constructible<outer_allocator_type, _OuterA2>::value
215 >::type> 230 >::type>
216 _LIBCPP_INLINE_VISIBILITY 231 _LIBCPP_INLINE_VISIBILITY
217 __scoped_allocator_storage(_OuterA2&& __outerAlloc, 232 __scoped_allocator_storage(_OuterA2&& __outer_alloc,
218 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT 233 const _InnerAllocs& ...__inner_allocs) _NOEXCEPT
219 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)), 234 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outer_alloc)),
220 __inner_(__innerAllocs...) {} 235 __inner_(__inner_allocs...) {}
221 236
222 template <class _OuterA2, 237 template <class _OuterA2,
223 class = typename enable_if< 238 class = typename enable_if<
224 is_constructible<outer_allocator_type, const _OuterA2&>::value 239 is_constructible<outer_allocator_type, const _OuterA2&>::value
225 >::type> 240 >::type>
293 template <class _OuterA2, 308 template <class _OuterA2,
294 class = typename enable_if< 309 class = typename enable_if<
295 is_constructible<outer_allocator_type, _OuterA2>::value 310 is_constructible<outer_allocator_type, _OuterA2>::value
296 >::type> 311 >::type>
297 _LIBCPP_INLINE_VISIBILITY 312 _LIBCPP_INLINE_VISIBILITY
298 __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT 313 __scoped_allocator_storage(_OuterA2&& __outer_alloc) _NOEXCEPT
299 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {} 314 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outer_alloc)) {}
300 315
301 template <class _OuterA2, 316 template <class _OuterA2,
302 class = typename enable_if< 317 class = typename enable_if<
303 is_constructible<outer_allocator_type, const _OuterA2&>::value 318 is_constructible<outer_allocator_type, const _OuterA2&>::value
304 >::type> 319 >::type>
372 }; 387 };
373 388
374 template <class _Alloc> 389 template <class _Alloc>
375 struct __outermost<_Alloc, true> 390 struct __outermost<_Alloc, true>
376 { 391 {
377 typedef typename remove_reference 392 typedef __libcpp_remove_reference_t
378 < 393 <
379 decltype(declval<_Alloc>().outer_allocator()) 394 decltype(declval<_Alloc>().outer_allocator())
380 >::type _OuterAlloc; 395 > _OuterAlloc;
381 typedef typename __outermost<_OuterAlloc>::type type; 396 typedef typename __outermost<_OuterAlloc>::type type;
382 _LIBCPP_INLINE_VISIBILITY 397 _LIBCPP_INLINE_VISIBILITY
383 type& operator()(_Alloc& __a) const _NOEXCEPT 398 type& operator()(_Alloc& __a) const _NOEXCEPT
384 {return __outermost<_OuterAlloc>()(__a.outer_allocator());} 399 {return __outermost<_OuterAlloc>()(__a.outer_allocator());}
385 }; 400 };
437 template <class _OuterA2, 452 template <class _OuterA2,
438 class = typename enable_if< 453 class = typename enable_if<
439 is_constructible<outer_allocator_type, _OuterA2>::value 454 is_constructible<outer_allocator_type, _OuterA2>::value
440 >::type> 455 >::type>
441 _LIBCPP_INLINE_VISIBILITY 456 _LIBCPP_INLINE_VISIBILITY
442 scoped_allocator_adaptor(_OuterA2&& __outerAlloc, 457 scoped_allocator_adaptor(_OuterA2&& __outer_alloc,
443 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT 458 const _InnerAllocs& ...__inner_allocs) _NOEXCEPT
444 : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {} 459 : base(_VSTD::forward<_OuterA2>(__outer_alloc), __inner_allocs...) {}
445 // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default; 460 // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
446 template <class _OuterA2, 461 template <class _OuterA2,
447 class = typename enable_if< 462 class = typename enable_if<
448 is_constructible<outer_allocator_type, const _OuterA2&>::value 463 is_constructible<outer_allocator_type, const _OuterA2&>::value
449 >::type> 464 >::type>
494 509
495 _LIBCPP_INLINE_VISIBILITY 510 _LIBCPP_INLINE_VISIBILITY
496 size_type max_size() const 511 size_type max_size() const
497 {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());} 512 {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
498 513
514 #if _LIBCPP_STD_VER >= 20
515 template <class _Type, class... _Args>
516 _LIBCPP_HIDE_FROM_ABI void construct(_Type* __ptr, _Args&&... __args) {
517 using _OM = __outermost<outer_allocator_type>;
518 std::apply(
519 [__ptr, this](auto&&... __newargs) {
520 allocator_traits<typename _OM::type>::construct(
521 _OM()(outer_allocator()), __ptr, std::forward<decltype(__newargs)>(__newargs)...);
522 },
523 std::uses_allocator_construction_args<_Type>(inner_allocator(), std::forward<_Args>(__args)...));
524 }
525 #else
499 template <class _Tp, class... _Args> 526 template <class _Tp, class... _Args>
500 _LIBCPP_INLINE_VISIBILITY 527 _LIBCPP_INLINE_VISIBILITY
501 void construct(_Tp* __p, _Args&& ...__args) 528 void construct(_Tp* __p, _Args&& ...__args)
502 {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), 529 {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(),
503 __p, _VSTD::forward<_Args>(__args)...);} 530 __p, _VSTD::forward<_Args>(__args)...);}
548 void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) { 575 void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) {
549 construct(__p, piecewise_construct, 576 construct(__p, piecewise_construct,
550 _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)), 577 _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)),
551 _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second))); 578 _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second)));
552 } 579 }
580 #endif
553 581
554 template <class _Tp> 582 template <class _Tp>
555 _LIBCPP_INLINE_VISIBILITY 583 _LIBCPP_INLINE_VISIBILITY
556 void destroy(_Tp* __p) 584 void destroy(_Tp* __p)
557 { 585 {
647 } 675 }
648 676
649 template <class...> friend class __scoped_allocator_storage; 677 template <class...> friend class __scoped_allocator_storage;
650 }; 678 };
651 679
680 #if _LIBCPP_STD_VER > 14
681 template<class _OuterAlloc, class... _InnerAllocs>
682 scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...)
683 -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>;
684 #endif
685
652 template <class _OuterA1, class _OuterA2> 686 template <class _OuterA1, class _OuterA2>
653 inline _LIBCPP_INLINE_VISIBILITY 687 inline _LIBCPP_INLINE_VISIBILITY
654 bool 688 bool
655 operator==(const scoped_allocator_adaptor<_OuterA1>& __a, 689 operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
656 const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT 690 const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT
679 713
680 #endif // !defined(_LIBCPP_CXX03_LANG) 714 #endif // !defined(_LIBCPP_CXX03_LANG)
681 715
682 _LIBCPP_END_NAMESPACE_STD 716 _LIBCPP_END_NAMESPACE_STD
683 717
718 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
719 # include <atomic>
720 # include <climits>
721 # include <concepts>
722 # include <cstring>
723 # include <ctime>
724 # include <iterator>
725 # include <memory>
726 # include <ratio>
727 # include <stdexcept>
728 # include <variant>
729 #endif
730
684 #endif // _LIBCPP_SCOPED_ALLOCATOR 731 #endif // _LIBCPP_SCOPED_ALLOCATOR