|
| 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___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H |
| 11 | +#define _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H |
| 12 | + |
| 13 | +#include <__concepts/constructible.h> |
| 14 | +#include <__config> |
| 15 | +#include <__function_like.h> |
| 16 | +#include <__iterator/incrementable_traits.h> |
| 17 | +#include <__iterator/iterator_traits.h> |
| 18 | +#include <__iterator/readable_traits.h> |
| 19 | +#include <__memory/concepts.h> |
| 20 | +#include <__memory/uninitialized_algorithms.h> |
| 21 | +#include <__ranges/access.h> |
| 22 | +#include <__ranges/concepts.h> |
| 23 | +#include <__ranges/dangling.h> |
| 24 | +#include <type_traits> |
| 25 | + |
| 26 | +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 27 | +#pragma GCC system_header |
| 28 | +#endif |
| 29 | + |
| 30 | +_LIBCPP_BEGIN_NAMESPACE_STD |
| 31 | + |
| 32 | +#if !defined(_LIBCPP_HAS_NO_RANGES) |
| 33 | +namespace ranges { |
| 34 | + |
| 35 | +// uninitialized_default_construct |
| 36 | + |
| 37 | +namespace __uninitialized_default_construct { |
| 38 | + |
| 39 | +struct __fn final : private __function_like { |
| 40 | + |
| 41 | + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} |
| 42 | + |
| 43 | + template <__nothrow_forward_iterator _ForwardIterator, |
| 44 | + __nothrow_sentinel_for<_ForwardIterator> _Sentinel> |
| 45 | + requires default_initializable<iter_value_t<_ForwardIterator>> |
| 46 | + _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { |
| 47 | + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; |
| 48 | + return _VSTD::__uninitialized_default_construct<_ValueType>(__first, __last); |
| 49 | + } |
| 50 | + |
| 51 | + template <__nothrow_forward_range _ForwardRange> |
| 52 | + requires default_initializable<range_value_t<_ForwardRange>> |
| 53 | + borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const { |
| 54 | + return (*this)(ranges::begin(__range), ranges::end(__range)); |
| 55 | + } |
| 56 | + |
| 57 | +}; |
| 58 | + |
| 59 | +} // namespace __uninitialized_default_construct_ns |
| 60 | + |
| 61 | +inline namespace __cpo { |
| 62 | +inline constexpr auto uninitialized_default_construct = |
| 63 | + __uninitialized_default_construct::__fn(__function_like::__tag()); |
| 64 | +} // namespace __cpo |
| 65 | + |
| 66 | +// uninitialized_default_construct_n |
| 67 | + |
| 68 | +namespace __uninitialized_default_construct_n { |
| 69 | + |
| 70 | +struct __fn final : private __function_like { |
| 71 | + |
| 72 | + constexpr explicit __fn(__tag __x) noexcept : |
| 73 | + __function_like(__x) {} |
| 74 | + |
| 75 | + template <__nothrow_forward_iterator _ForwardIterator> |
| 76 | + requires default_initializable<iter_value_t<_ForwardIterator>> |
| 77 | + _ForwardIterator operator()(_ForwardIterator __first, |
| 78 | + iter_difference_t<_ForwardIterator> __n) const { |
| 79 | + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; |
| 80 | + return _VSTD::__uninitialized_default_construct_n<_ValueType>(__first, __n); |
| 81 | + } |
| 82 | + |
| 83 | +}; |
| 84 | + |
| 85 | +} // namespace __uninitialized_default_construct_n_ns |
| 86 | + |
| 87 | +inline namespace __cpo { |
| 88 | +inline constexpr auto uninitialized_default_construct_n = |
| 89 | + __uninitialized_default_construct_n::__fn(__function_like::__tag()); |
| 90 | +} // namespace __cpo |
| 91 | + |
| 92 | +} // namespace ranges |
| 93 | +#endif // !defined(_LIBCPP_HAS_NO_RANGES) |
| 94 | + |
| 95 | +_LIBCPP_END_NAMESPACE_STD |
| 96 | + |
| 97 | +#endif // _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H |
0 commit comments