File indexing completed on 2026-05-03 08:13:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
0011 #define _LIBCPP___CXX03___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
0012
0013 #include <__cxx03/__algorithm/in_out_result.h>
0014 #include <__cxx03/__concepts/constructible.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/incrementable_traits.h>
0018 #include <__cxx03/__iterator/iter_move.h>
0019 #include <__cxx03/__iterator/iterator_traits.h>
0020 #include <__cxx03/__iterator/readable_traits.h>
0021 #include <__cxx03/__memory/concepts.h>
0022 #include <__cxx03/__memory/uninitialized_algorithms.h>
0023 #include <__cxx03/__ranges/access.h>
0024 #include <__cxx03/__ranges/concepts.h>
0025 #include <__cxx03/__ranges/dangling.h>
0026 #include <__cxx03/__type_traits/remove_reference.h>
0027 #include <__cxx03/__utility/move.h>
0028 #include <__cxx03/new>
0029
0030 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0031 # pragma GCC system_header
0032 #endif
0033
0034 _LIBCPP_PUSH_MACROS
0035 #include <__cxx03/__undef_macros>
0036
0037 _LIBCPP_BEGIN_NAMESPACE_STD
0038
0039 #if _LIBCPP_STD_VER >= 20
0040
0041 namespace ranges {
0042
0043
0044
0045 namespace __uninitialized_default_construct {
0046
0047 struct __fn {
0048 template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
0049 requires default_initializable<iter_value_t<_ForwardIterator>>
0050 _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
0051 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
0052 return std::__uninitialized_default_construct<_ValueType>(std::move(__first), std::move(__last));
0053 }
0054
0055 template <__nothrow_forward_range _ForwardRange>
0056 requires default_initializable<range_value_t<_ForwardRange>>
0057 _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
0058 return (*this)(ranges::begin(__range), ranges::end(__range));
0059 }
0060 };
0061
0062 }
0063
0064 inline namespace __cpo {
0065 inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{};
0066 }
0067
0068
0069
0070 namespace __uninitialized_default_construct_n {
0071
0072 struct __fn {
0073 template <__nothrow_forward_iterator _ForwardIterator>
0074 requires default_initializable<iter_value_t<_ForwardIterator>>
0075 _LIBCPP_HIDE_FROM_ABI _ForwardIterator
0076 operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n) const {
0077 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
0078 return std::__uninitialized_default_construct_n<_ValueType>(std::move(__first), __n);
0079 }
0080 };
0081
0082 }
0083
0084 inline namespace __cpo {
0085 inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{};
0086 }
0087
0088
0089
0090 namespace __uninitialized_value_construct {
0091
0092 struct __fn {
0093 template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
0094 requires default_initializable<iter_value_t<_ForwardIterator>>
0095 _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
0096 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
0097 return std::__uninitialized_value_construct<_ValueType>(std::move(__first), std::move(__last));
0098 }
0099
0100 template <__nothrow_forward_range _ForwardRange>
0101 requires default_initializable<range_value_t<_ForwardRange>>
0102 _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
0103 return (*this)(ranges::begin(__range), ranges::end(__range));
0104 }
0105 };
0106
0107 }
0108
0109 inline namespace __cpo {
0110 inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{};
0111 }
0112
0113
0114
0115 namespace __uninitialized_value_construct_n {
0116
0117 struct __fn {
0118 template <__nothrow_forward_iterator _ForwardIterator>
0119 requires default_initializable<iter_value_t<_ForwardIterator>>
0120 _LIBCPP_HIDE_FROM_ABI _ForwardIterator
0121 operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n) const {
0122 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
0123 return std::__uninitialized_value_construct_n<_ValueType>(std::move(__first), __n);
0124 }
0125 };
0126
0127 }
0128
0129 inline namespace __cpo {
0130 inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{};
0131 }
0132
0133
0134
0135 namespace __uninitialized_fill {
0136
0137 struct __fn {
0138 template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel, class _Tp>
0139 requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
0140 _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const {
0141 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
0142 return std::__uninitialized_fill<_ValueType>(std::move(__first), std::move(__last), __x);
0143 }
0144
0145 template <__nothrow_forward_range _ForwardRange, class _Tp>
0146 requires constructible_from<range_value_t<_ForwardRange>, const _Tp&>
0147 _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range, const _Tp& __x) const {
0148 return (*this)(ranges::begin(__range), ranges::end(__range), __x);
0149 }
0150 };
0151
0152 }
0153
0154 inline namespace __cpo {
0155 inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{};
0156 }
0157
0158
0159
0160 namespace __uninitialized_fill_n {
0161
0162 struct __fn {
0163 template <__nothrow_forward_iterator _ForwardIterator, class _Tp>
0164 requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
0165 _LIBCPP_HIDE_FROM_ABI _ForwardIterator
0166 operator()(_ForwardIterator __first, iter_difference_t<_ForwardIterator> __n, const _Tp& __x) const {
0167 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
0168 return std::__uninitialized_fill_n<_ValueType>(std::move(__first), __n, __x);
0169 }
0170 };
0171
0172 }
0173
0174 inline namespace __cpo {
0175 inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{};
0176 }
0177
0178
0179
0180 template <class _InputIterator, class _OutputIterator>
0181 using uninitialized_copy_result = in_out_result<_InputIterator, _OutputIterator>;
0182
0183 namespace __uninitialized_copy {
0184
0185 struct __fn {
0186 template <input_iterator _InputIterator,
0187 sentinel_for<_InputIterator> _Sentinel1,
0188 __nothrow_forward_iterator _OutputIterator,
0189 __nothrow_sentinel_for<_OutputIterator> _Sentinel2>
0190 requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
0191 _LIBCPP_HIDE_FROM_ABI uninitialized_copy_result<_InputIterator, _OutputIterator>
0192 operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
0193 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
0194
0195 auto __stop_copying = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; };
0196 auto __result = std::__uninitialized_copy<_ValueType>(
0197 std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __stop_copying);
0198 return {std::move(__result.first), std::move(__result.second)};
0199 }
0200
0201 template <input_range _InputRange, __nothrow_forward_range _OutputRange>
0202 requires constructible_from<range_value_t<_OutputRange>, range_reference_t<_InputRange>>
0203 _LIBCPP_HIDE_FROM_ABI uninitialized_copy_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>>
0204 operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const {
0205 return (*this)(
0206 ranges::begin(__in_range), ranges::end(__in_range), ranges::begin(__out_range), ranges::end(__out_range));
0207 }
0208 };
0209
0210 }
0211
0212 inline namespace __cpo {
0213 inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{};
0214 }
0215
0216
0217
0218 template <class _InputIterator, class _OutputIterator>
0219 using uninitialized_copy_n_result = in_out_result<_InputIterator, _OutputIterator>;
0220
0221 namespace __uninitialized_copy_n {
0222
0223 struct __fn {
0224 template <input_iterator _InputIterator,
0225 __nothrow_forward_iterator _OutputIterator,
0226 __nothrow_sentinel_for<_OutputIterator> _Sentinel>
0227 requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
0228 _LIBCPP_HIDE_FROM_ABI uninitialized_copy_n_result<_InputIterator, _OutputIterator>
0229 operator()(_InputIterator __ifirst,
0230 iter_difference_t<_InputIterator> __n,
0231 _OutputIterator __ofirst,
0232 _Sentinel __olast) const {
0233 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
0234 auto __stop_copying = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; };
0235 auto __result =
0236 std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __stop_copying);
0237 return {std::move(__result.first), std::move(__result.second)};
0238 }
0239 };
0240
0241 }
0242
0243 inline namespace __cpo {
0244 inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{};
0245 }
0246
0247
0248
0249 template <class _InputIterator, class _OutputIterator>
0250 using uninitialized_move_result = in_out_result<_InputIterator, _OutputIterator>;
0251
0252 namespace __uninitialized_move {
0253
0254 struct __fn {
0255 template <input_iterator _InputIterator,
0256 sentinel_for<_InputIterator> _Sentinel1,
0257 __nothrow_forward_iterator _OutputIterator,
0258 __nothrow_sentinel_for<_OutputIterator> _Sentinel2>
0259 requires constructible_from<iter_value_t<_OutputIterator>, iter_rvalue_reference_t<_InputIterator>>
0260 _LIBCPP_HIDE_FROM_ABI uninitialized_move_result<_InputIterator, _OutputIterator>
0261 operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
0262 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
0263 auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
0264 auto __stop_moving = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; };
0265 auto __result = std::__uninitialized_move<_ValueType>(
0266 std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __stop_moving, __iter_move);
0267 return {std::move(__result.first), std::move(__result.second)};
0268 }
0269
0270 template <input_range _InputRange, __nothrow_forward_range _OutputRange>
0271 requires constructible_from<range_value_t<_OutputRange>, range_rvalue_reference_t<_InputRange>>
0272 _LIBCPP_HIDE_FROM_ABI uninitialized_move_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>>
0273 operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const {
0274 return (*this)(
0275 ranges::begin(__in_range), ranges::end(__in_range), ranges::begin(__out_range), ranges::end(__out_range));
0276 }
0277 };
0278
0279 }
0280
0281 inline namespace __cpo {
0282 inline constexpr auto uninitialized_move = __uninitialized_move::__fn{};
0283 }
0284
0285
0286
0287 template <class _InputIterator, class _OutputIterator>
0288 using uninitialized_move_n_result = in_out_result<_InputIterator, _OutputIterator>;
0289
0290 namespace __uninitialized_move_n {
0291
0292 struct __fn {
0293 template <input_iterator _InputIterator,
0294 __nothrow_forward_iterator _OutputIterator,
0295 __nothrow_sentinel_for<_OutputIterator> _Sentinel>
0296 requires constructible_from<iter_value_t<_OutputIterator>, iter_rvalue_reference_t<_InputIterator>>
0297 _LIBCPP_HIDE_FROM_ABI uninitialized_move_n_result<_InputIterator, _OutputIterator>
0298 operator()(_InputIterator __ifirst,
0299 iter_difference_t<_InputIterator> __n,
0300 _OutputIterator __ofirst,
0301 _Sentinel __olast) const {
0302 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
0303 auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
0304 auto __stop_moving = [&__olast](auto&& __out_iter) -> bool { return __out_iter == __olast; };
0305 auto __result = std::__uninitialized_move_n<_ValueType>(
0306 std::move(__ifirst), __n, std::move(__ofirst), __stop_moving, __iter_move);
0307 return {std::move(__result.first), std::move(__result.second)};
0308 }
0309 };
0310
0311 }
0312
0313 inline namespace __cpo {
0314 inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{};
0315 }
0316
0317 }
0318
0319 #endif
0320
0321 _LIBCPP_END_NAMESPACE_STD
0322
0323 _LIBCPP_POP_MACROS
0324
0325 #endif