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