Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:36

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___MEMORY_USES_ALLOCATOR_CONSTRUCTION_H
0010 #define _LIBCPP___CXX03___MEMORY_USES_ALLOCATOR_CONSTRUCTION_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__memory/construct_at.h>
0014 #include <__cxx03/__memory/uses_allocator.h>
0015 #include <__cxx03/__tuple/tuple_like_no_subrange.h>
0016 #include <__cxx03/__type_traits/enable_if.h>
0017 #include <__cxx03/__type_traits/is_same.h>
0018 #include <__cxx03/__type_traits/remove_cv.h>
0019 #include <__cxx03/__utility/declval.h>
0020 #include <__cxx03/__utility/pair.h>
0021 #include <__cxx03/tuple>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_PUSH_MACROS
0028 #include <__cxx03/__undef_macros>
0029 
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031 
0032 #if _LIBCPP_STD_VER >= 17
0033 
0034 template <class _Type>
0035 inline constexpr bool __is_std_pair = false;
0036 
0037 template <class _Type1, class _Type2>
0038 inline constexpr bool __is_std_pair<pair<_Type1, _Type2>> = true;
0039 
0040 template <class _Tp>
0041 inline constexpr bool __is_cv_std_pair = __is_std_pair<remove_cv_t<_Tp>>;
0042 
0043 template <class _Type, class _Alloc, class... _Args, __enable_if_t<!__is_cv_std_pair<_Type>, int> = 0>
0044 _LIBCPP_HIDE_FROM_ABI constexpr auto
0045 __uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noexcept {
0046   if constexpr (!uses_allocator_v<remove_cv_t<_Type>, _Alloc> && is_constructible_v<_Type, _Args...>) {
0047     return std::forward_as_tuple(std::forward<_Args>(__args)...);
0048   } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> &&
0049                        is_constructible_v<_Type, allocator_arg_t, const _Alloc&, _Args...>) {
0050     return tuple<allocator_arg_t, const _Alloc&, _Args&&...>(allocator_arg, __alloc, std::forward<_Args>(__args)...);
0051   } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> &&
0052                        is_constructible_v<_Type, _Args..., const _Alloc&>) {
0053     return std::forward_as_tuple(std::forward<_Args>(__args)..., __alloc);
0054   } else {
0055     static_assert(
0056         sizeof(_Type) + 1 == 0, "If uses_allocator_v<Type> is true, the type has to be allocator-constructible");
0057   }
0058 }
0059 
0060 template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0061 _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(
0062     const _Alloc& __alloc, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept {
0063   return std::make_tuple(
0064       piecewise_construct,
0065       std::apply(
0066           [&__alloc](auto&&... __args1) {
0067             return std::__uses_allocator_construction_args<typename _Pair::first_type>(
0068                 __alloc, std::forward<decltype(__args1)>(__args1)...);
0069           },
0070           std::forward<_Tuple1>(__x)),
0071       std::apply(
0072           [&__alloc](auto&&... __args2) {
0073             return std::__uses_allocator_construction_args<typename _Pair::second_type>(
0074                 __alloc, std::forward<decltype(__args2)>(__args2)...);
0075           },
0076           std::forward<_Tuple2>(__y)));
0077 }
0078 
0079 template <class _Pair, class _Alloc, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0080 _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc) noexcept {
0081   return std::__uses_allocator_construction_args<_Pair>(__alloc, piecewise_construct, tuple<>{}, tuple<>{});
0082 }
0083 
0084 template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0085 _LIBCPP_HIDE_FROM_ABI constexpr auto
0086 __uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) noexcept {
0087   return std::__uses_allocator_construction_args<_Pair>(
0088       __alloc,
0089       piecewise_construct,
0090       std::forward_as_tuple(std::forward<_Up>(__u)),
0091       std::forward_as_tuple(std::forward<_Vp>(__v)));
0092 }
0093 
0094 #  if _LIBCPP_STD_VER >= 23
0095 template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0096 _LIBCPP_HIDE_FROM_ABI constexpr auto
0097 __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair) noexcept {
0098   return std::__uses_allocator_construction_args<_Pair>(
0099       __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
0100 }
0101 #  endif
0102 
0103 template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0104 _LIBCPP_HIDE_FROM_ABI constexpr auto
0105 __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>& __pair) noexcept {
0106   return std::__uses_allocator_construction_args<_Pair>(
0107       __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
0108 }
0109 
0110 template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0111 _LIBCPP_HIDE_FROM_ABI constexpr auto
0112 __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pair) noexcept {
0113   return std::__uses_allocator_construction_args<_Pair>(
0114       __alloc,
0115       piecewise_construct,
0116       std::forward_as_tuple(std::get<0>(std::move(__pair))),
0117       std::forward_as_tuple(std::get<1>(std::move(__pair))));
0118 }
0119 
0120 #  if _LIBCPP_STD_VER >= 23
0121 template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0122 _LIBCPP_HIDE_FROM_ABI constexpr auto
0123 __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>&& __pair) noexcept {
0124   return std::__uses_allocator_construction_args<_Pair>(
0125       __alloc,
0126       piecewise_construct,
0127       std::forward_as_tuple(std::get<0>(std::move(__pair))),
0128       std::forward_as_tuple(std::get<1>(std::move(__pair))));
0129 }
0130 
0131 template <class _Pair, class _Alloc, __pair_like_no_subrange _PairLike, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
0132 _LIBCPP_HIDE_FROM_ABI constexpr auto
0133 __uses_allocator_construction_args(const _Alloc& __alloc, _PairLike&& __p) noexcept {
0134   return std::__uses_allocator_construction_args<_Pair>(
0135       __alloc,
0136       piecewise_construct,
0137       std::forward_as_tuple(std::get<0>(std::forward<_PairLike>(__p))),
0138       std::forward_as_tuple(std::get<1>(std::forward<_PairLike>(__p))));
0139 }
0140 #  endif
0141 
0142 namespace __uses_allocator_detail {
0143 
0144 template <class _Ap, class _Bp>
0145 void __fun(const pair<_Ap, _Bp>&);
0146 
0147 template <class _Tp>
0148 decltype(__uses_allocator_detail::__fun(std::declval<_Tp>()), true_type()) __convertible_to_const_pair_ref_impl(int);
0149 
0150 template <class>
0151 false_type __convertible_to_const_pair_ref_impl(...);
0152 
0153 template <class _Tp>
0154 inline constexpr bool __convertible_to_const_pair_ref =
0155     decltype(__uses_allocator_detail::__convertible_to_const_pair_ref_impl<_Tp>(0))::value;
0156 
0157 #  if _LIBCPP_STD_VER >= 23
0158 template <class _Tp, class _Up>
0159 inline constexpr bool __uses_allocator_constraints =
0160     __is_cv_std_pair<_Tp> && !__pair_like_no_subrange<_Up> && !__convertible_to_const_pair_ref<_Up>;
0161 #  else
0162 template <class _Tp, class _Up>
0163 inline constexpr bool __uses_allocator_constraints = __is_cv_std_pair<_Tp> && !__convertible_to_const_pair_ref<_Up>;
0164 #  endif
0165 
0166 } // namespace __uses_allocator_detail
0167 
0168 template < class _Pair,
0169            class _Alloc,
0170            class _Type,
0171            __enable_if_t<__uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int> = 0>
0172 _LIBCPP_HIDE_FROM_ABI constexpr auto
0173 __uses_allocator_construction_args(const _Alloc& __alloc, _Type&& __value) noexcept;
0174 
0175 template <class _Type, class _Alloc, class... _Args>
0176 _LIBCPP_HIDE_FROM_ABI constexpr _Type __make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args);
0177 
0178 template < class _Pair,
0179            class _Alloc,
0180            class _Type,
0181            __enable_if_t< __uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int>>
0182 _LIBCPP_HIDE_FROM_ABI constexpr auto
0183 __uses_allocator_construction_args(const _Alloc& __alloc, _Type&& __value) noexcept {
0184   struct __pair_constructor {
0185     using _PairMutable = remove_cv_t<_Pair>;
0186 
0187     _LIBCPP_HIDDEN constexpr auto __do_construct(const _PairMutable& __pair) const {
0188       return std::__make_obj_using_allocator<_PairMutable>(__alloc_, __pair);
0189     }
0190 
0191     _LIBCPP_HIDDEN constexpr auto __do_construct(_PairMutable&& __pair) const {
0192       return std::__make_obj_using_allocator<_PairMutable>(__alloc_, std::move(__pair));
0193     }
0194 
0195     const _Alloc& __alloc_;
0196     _Type& __value_;
0197 
0198     _LIBCPP_HIDDEN constexpr operator _PairMutable() const { return __do_construct(std::forward<_Type>(__value_)); }
0199   };
0200 
0201   return std::make_tuple(__pair_constructor{__alloc, __value});
0202 }
0203 
0204 template <class _Type, class _Alloc, class... _Args>
0205 _LIBCPP_HIDE_FROM_ABI constexpr _Type __make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args) {
0206   return std::make_from_tuple<_Type>(
0207       std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...));
0208 }
0209 
0210 template <class _Type, class _Alloc, class... _Args>
0211 _LIBCPP_HIDE_FROM_ABI constexpr _Type*
0212 __uninitialized_construct_using_allocator(_Type* __ptr, const _Alloc& __alloc, _Args&&... __args) {
0213   return std::apply(
0214       [&__ptr](auto&&... __xs) { return std::__construct_at(__ptr, std::forward<decltype(__xs)>(__xs)...); },
0215       std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...));
0216 }
0217 
0218 #endif // _LIBCPP_STD_VER >= 17
0219 
0220 #if _LIBCPP_STD_VER >= 20
0221 
0222 template <class _Type, class _Alloc, class... _Args>
0223 _LIBCPP_HIDE_FROM_ABI constexpr auto uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noexcept
0224     -> decltype(std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...)) {
0225   return /*--*/ std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...);
0226 }
0227 
0228 template <class _Type, class _Alloc, class... _Args>
0229 _LIBCPP_HIDE_FROM_ABI constexpr auto make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args)
0230     -> decltype(std::__make_obj_using_allocator<_Type>(__alloc, std::forward<_Args>(__args)...)) {
0231   return /*--*/ std::__make_obj_using_allocator<_Type>(__alloc, std::forward<_Args>(__args)...);
0232 }
0233 
0234 template <class _Type, class _Alloc, class... _Args>
0235 _LIBCPP_HIDE_FROM_ABI constexpr auto
0236 uninitialized_construct_using_allocator(_Type* __ptr, const _Alloc& __alloc, _Args&&... __args)
0237     -> decltype(std::__uninitialized_construct_using_allocator(__ptr, __alloc, std::forward<_Args>(__args)...)) {
0238   return /*--*/ std::__uninitialized_construct_using_allocator(__ptr, __alloc, std::forward<_Args>(__args)...);
0239 }
0240 
0241 #endif // _LIBCPP_STD_VER >= 20
0242 
0243 _LIBCPP_END_NAMESPACE_STD
0244 
0245 _LIBCPP_POP_MACROS
0246 
0247 #endif // _LIBCPP___CXX03___MEMORY_USES_ALLOCATOR_CONSTRUCTION_H