diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -59,6 +59,7 @@ __algorithm/pop_heap.h __algorithm/prev_permutation.h __algorithm/push_heap.h + __algorithm/ranges_equal.h __algorithm/remove_copy_if.h __algorithm/remove_copy.h __algorithm/remove_if.h @@ -188,6 +189,7 @@ __hash_table __iterator/access.h __iterator/advance.h + __iterator/algorithm_concepts.h __iterator/back_insert_iterator.h __iterator/common_iterator.h __iterator/concepts.h @@ -199,6 +201,9 @@ __iterator/erase_if_container.h __iterator/front_insert_iterator.h __iterator/incrementable_traits.h + __iterator/indirectly_copyable.h + __iterator/indirectly_movable.h + __iterator/indirectly_swappable.h __iterator/insert_iterator.h __iterator/istream_iterator.h __iterator/istreambuf_iterator.h @@ -212,6 +217,7 @@ __iterator/ostreambuf_iterator.h __iterator/prev.h __iterator/projected.h + __iterator/ranges_distance.h __iterator/readable_traits.h __iterator/reverse_access.h __iterator/reverse_iterator.h @@ -296,6 +302,7 @@ __ranges/counted.h __ranges/dangling.h __ranges/data.h + __ranges/drop.h __ranges/drop_view.h __ranges/empty_view.h __ranges/empty.h @@ -310,6 +317,7 @@ __ranges/single_view.h __ranges/size.h __ranges/subrange.h + __ranges/take.h __ranges/take_view.h __ranges/transform_view.h __ranges/view_interface.h diff --git a/libcxx/include/__algorithm/ranges_equal.h b/libcxx/include/__algorithm/ranges_equal.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__algorithm/ranges_equal.h @@ -0,0 +1,98 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_H +#define _LIBCPP___ALGORITHM_RANGES_EQUAL_H + +#include <__config> +#include <__iterator/algorithm_concepts.h> +#include <__iterator/concepts.h> +#include <__iterator/ranges_distance.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANGES) + +// [alg.equal] + +namespace ranges { + +namespace __equal { + + struct __fn { + template _Sent1, + input_or_output_iterator _It2, sentinel_for<_It2> _Sent2, + class _Pred = ranges::equal_to, + class _Proj1 = identity, class _Proj2 = identity> + requires indirectly_comparable<_It1, _It2, _Pred, _Proj1, _Proj2> + constexpr bool operator()(_It1 __first1, _Sent1 __last1, + _It2 __first2, _Sent2 __last2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { + if constexpr (sized_sentinel_for<_Sent1, _It1> && sized_sentinel_for<_Sent2, _It2>) { + if (ranges::distance(__first1, __last1) != ranges::distance(__first2, __last2)) + return false; + } + while (__first1 != __last1) { + if (__first2 == __last2) + return false; + if (!bool(_VSTD::invoke(__pred, _VSTD::invoke(__proj1, *__first1), _VSTD::invoke(__proj2, *__first2)))) + return false; + ++__first1; + ++__first2; + } + return (__first2 == __last2); + } + + template + requires indirectly_comparable, iterator_t<_Rp2>, _Pred, _Proj1, _Proj2> + constexpr bool operator()(_Rp1&& __r1, _Rp2&& __r2, + _Pred __pred = {}, + _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { + if constexpr (sized_range<_Rp1> && sized_range<_Rp2>) { + if (ranges::distance(__r1) != ranges::distance(__r2)) + return false; + } + auto __first1 = ranges::begin(__r1); + auto __last1 = ranges::end(__r1); + auto __first2 = ranges::begin(__r2); + auto __last2 = ranges::end(__r2); + while (__first1 != __last1) { + if (__first2 == __last2) + return false; + if (!bool(_VSTD::invoke(__pred, _VSTD::invoke(__proj1, *__first1), _VSTD::invoke(__proj2, *__first2)))) + return false; + ++__first1; + ++__first2; + } + return (__first2 == __last2); + } + }; + +} // namespace __equal + +inline namespace __cpo { + inline constexpr auto equal = __equal::__fn{}; +} // namespace __cpo + +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H diff --git a/libcxx/include/__iterator/algorithm_concepts.h b/libcxx/include/__iterator/algorithm_concepts.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/algorithm_concepts.h @@ -0,0 +1,74 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ITERATOR_ALGORITHM_CONCEPTS_H +#define _LIBCPP___ITERATOR_ALGORITHM_CONCEPTS_H + +#include <__config> +#include <__concepts/copyable.h> +#include <__concepts/movable.h> +#include <__functional/identity.h> +#include <__functional/ranges_operations.h> +#include <__iterator/concepts.h> +#include <__iterator/indirectly_copyable.h> +#include <__iterator/indirectly_movable.h> +#include <__iterator/indirectly_swappable.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/projected.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +// [alg.req.ind.cmp] + +template +concept indirectly_comparable = + indirect_binary_predicate<_Pred, projected<_It1, _Proj1>, projected<_It2, _Proj2>>; + +// [alg.req.permutable] + +template +concept permutable = + forward_iterator<_In> && + indirectly_movable_storable<_In, _In> && + indirectly_swappable<_In, _In>; + +// [alg.req.mergeable] + +#if !defined(_LIBCPP_HAS_NO_RANGES) + +template +concept mergeable = + input_iterator<_In1> && + input_iterator<_In2> && + weakly_incrementable<_Out> && + indirectly_copyable<_In1, _Out> && + indirectly_copyable<_In2, _Out> && + indirect_strict_weak_order<_Pred, projected<_In1, _Proj1>, projected<_In2, _Proj2>>; + +// [alg.req.sortable] + +template +concept sortable = + permutable<_It> && + indirect_strict_weak_order<_Pred, projected<_It, _Proj>>; + +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ITERATOR_ALGORITHM_CONCEPTS_H diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h --- a/libcxx/include/__iterator/common_iterator.h +++ b/libcxx/include/__iterator/common_iterator.h @@ -14,6 +14,7 @@ #include <__debug> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> +#include <__iterator/indirectly_swappable.h> #include <__iterator/iter_move.h> #include <__iterator/iter_swap.h> #include <__iterator/iterator_traits.h> diff --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h --- a/libcxx/include/__iterator/concepts.h +++ b/libcxx/include/__iterator/concepts.h @@ -243,22 +243,6 @@ requires (indirectly_readable<_Its> && ...) && invocable<_Fp, iter_reference_t<_Its>...> using indirect_result_t = invoke_result_t<_Fp, iter_reference_t<_Its>...>; -template -concept indirectly_movable = - indirectly_readable<_In> && - indirectly_writable<_Out, iter_rvalue_reference_t<_In>>; - -template -concept indirectly_movable_storable = - indirectly_movable<_In, _Out> && - indirectly_writable<_Out, iter_value_t<_In>> && - movable> && - constructible_from, iter_rvalue_reference_t<_In>> && - assignable_from&, iter_rvalue_reference_t<_In>>; - -// Note: indirectly_swappable is located in iter_swap.h to prevent a dependency cycle -// (both iter_swap and indirectly_swappable require indirectly_readable). - // clang-format on #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/libcxx/include/__iterator/counted_iterator.h b/libcxx/include/__iterator/counted_iterator.h --- a/libcxx/include/__iterator/counted_iterator.h +++ b/libcxx/include/__iterator/counted_iterator.h @@ -13,9 +13,10 @@ #include <__debug> #include <__iterator/concepts.h> #include <__iterator/default_sentinel.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/indirectly_swappable.h> #include <__iterator/iter_move.h> #include <__iterator/iter_swap.h> -#include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> #include <__memory/pointer_traits.h> diff --git a/libcxx/include/__iterator/indirectly_copyable.h b/libcxx/include/__iterator/indirectly_copyable.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/indirectly_copyable.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ITERATOR_INDIRECTLY_COPYABLE_H +#define _LIBCPP___ITERATOR_INDIRECTLY_COPYABLE_H + +#include <__config> +#include <__concepts/assignable.h> +#include <__concepts/constructible.h> +#include <__concepts/copyable.h> +#include <__iterator/concepts.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/readable_traits.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +// [alg.req.ind.copy] + +template +concept indirectly_copyable = + indirectly_readable<_In> && + indirectly_writable<_Out, iter_reference_t<_In>>; + +template +concept indirectly_copyable_storable = + indirectly_copyable<_In, _Out> && + indirectly_writable<_Out, iter_value_t<_In>&> && + indirectly_writable<_Out, const iter_value_t<_In>&> && + indirectly_writable<_Out, iter_value_t<_In>&&> && + indirectly_writable<_Out, const iter_value_t<_In>&&> && + copyable> && + constructible_from, iter_reference_t<_In>> && + assignable_from&, iter_reference_t<_In>>; + +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ITERATOR_INDIRECTLY_COPYABLE_H diff --git a/libcxx/include/__iterator/indirectly_movable.h b/libcxx/include/__iterator/indirectly_movable.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/indirectly_movable.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ITERATOR_INDIRECTLY_MOVABLE_H +#define _LIBCPP___ITERATOR_INDIRECTLY_MOVABLE_H + +#include <__config> +#include <__concepts/assignable.h> +#include <__concepts/constructible.h> +#include <__concepts/movable.h> +#include <__iterator/concepts.h> +#include <__iterator/iter_move.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/readable_traits.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +// [alg.req.ind.move] + +template +concept indirectly_movable = + indirectly_readable<_In> && + indirectly_writable<_Out, iter_rvalue_reference_t<_In>>; + +template +concept indirectly_movable_storable = + indirectly_movable<_In, _Out> && + indirectly_writable<_Out, iter_value_t<_In>> && + movable> && + constructible_from, iter_rvalue_reference_t<_In>> && + assignable_from&, iter_rvalue_reference_t<_In>>; + +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ITERATOR_INDIRECTLY_MOVABLE_H diff --git a/libcxx/include/__iterator/indirectly_swappable.h b/libcxx/include/__iterator/indirectly_swappable.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/indirectly_swappable.h @@ -0,0 +1,41 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ITERATOR_INDIRECTLY_SWAPPABLE_H +#define _LIBCPP___ITERATOR_INDIRECTLY_SWAPPABLE_H + +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/iter_swap.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_RANGES) + +// [alg.req.ind.swap] + +template +concept indirectly_swappable = + indirectly_readable<_It1> && indirectly_readable<_It2> && + requires (const _It1 __it1, const _It2 __it2) { + ranges::iter_swap(__it1, __it1); + ranges::iter_swap(__it2, __it2); + ranges::iter_swap(__it1, __it2); + ranges::iter_swap(__it2, __it1); + }; + +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ITERATOR_INDIRECTLY_SWAPPABLE_H diff --git a/libcxx/include/__iterator/iter_swap.h b/libcxx/include/__iterator/iter_swap.h --- a/libcxx/include/__iterator/iter_swap.h +++ b/libcxx/include/__iterator/iter_swap.h @@ -10,14 +10,15 @@ #define _LIBCPP___ITERATOR_ITER_SWAP_H #include <__config> +#include <__concepts/swappable.h> #include <__iterator/concepts.h> +#include <__iterator/indirectly_movable.h> #include <__iterator/iter_move.h> #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> #include <__ranges/access.h> #include <__utility/forward.h> #include <__utility/move.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -87,16 +88,6 @@ } // namespace ranges -template -concept indirectly_swappable = - indirectly_readable<_I1> && indirectly_readable<_I2> && - requires(const _I1 __i1, const _I2 __i2) { - ranges::iter_swap(__i1, __i1); - ranges::iter_swap(__i2, __i2); - ranges::iter_swap(__i1, __i2); - ranges::iter_swap(__i2, __i1); - }; - #endif // !defined(_LIBCPP_HAS_NO_RANGES) _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__iterator/iterator_traits.h b/libcxx/include/__iterator/iterator_traits.h --- a/libcxx/include/__iterator/iterator_traits.h +++ b/libcxx/include/__iterator/iterator_traits.h @@ -10,10 +10,16 @@ #ifndef _LIBCPP___ITERATOR_ITERATOR_TRAITS_H #define _LIBCPP___ITERATOR_ITERATOR_TRAITS_H +#include <__concepts/arithmetic.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/copyable.h> +#include <__concepts/equality_comparable.h> +#include <__concepts/same_as.h> +#include <__concepts/totally_ordered.h> #include <__config> #include <__iterator/incrementable_traits.h> #include <__iterator/readable_traits.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__iterator/ranges_distance.h b/libcxx/include/__iterator/ranges_distance.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/ranges_distance.h @@ -0,0 +1,72 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP___ITERATOR_RANGES_DISTANCE_H +#define _LIBCPP___ITERATOR_RANGES_DISTANCE_H + +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/incrementable_traits.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/size.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANGES) + +// [range.iter.op.distance] + +namespace ranges { + +namespace __distance { + + struct __fn { + template _Sent> + requires (!sized_sentinel_for<_Sent, _It>) + constexpr iter_difference_t<_It> operator()(_It __first, _Sent __last) const { + iter_difference_t<_It> __count = 0; + while (__first != __last) { + ++__first; + ++__count; + } + return __count; + } + + template _Sent> + constexpr iter_difference_t<_It> operator()(_It __first, _Sent __last) const { + return __last - __first; + } + + template + constexpr range_difference_t<_Rp> operator()(_Rp&& __r) const { + if constexpr (sized_range<_Rp>) { + return static_cast>(ranges::size(__r)); + } else { + return (*this)(ranges::begin(__r), ranges::end(__r)); + } + } + }; + +} // namespace __distance + +inline namespace __cpo { + inline constexpr auto distance = __distance::__fn{}; +} // namespace __cpo + +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ITERATOR_RANGES_DISTANCE_H diff --git a/libcxx/include/__ranges/counted.h b/libcxx/include/__ranges/counted.h --- a/libcxx/include/__ranges/counted.h +++ b/libcxx/include/__ranges/counted.h @@ -36,6 +36,7 @@ namespace ranges::views { namespace __counted { + template concept __explicitly_convertible = requires { _To(_From{}); @@ -79,7 +80,8 @@ return ranges::subrange(counted_iterator(_VSTD::forward<_Iter>(__it), __c), default_sentinel); } }; -} + +} // namespace __counted inline namespace __cpo { inline constexpr auto counted = __counted::__fn{}; diff --git a/libcxx/include/__ranges/drop.h b/libcxx/include/__ranges/drop.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__ranges/drop.h @@ -0,0 +1,151 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP___RANGES_DROP_H +#define _LIBCPP___RANGES_DROP_H + +#include <__algorithm/min.h> +#include <__concepts/constructible.h> +#include <__config> +#include <__functional/bind_back.h> +#include <__iterator/ranges_distance.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/drop_view.h> +#include <__ranges/empty_view.h> +#include <__ranges/iota_view.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/subrange.h> +#include <__utility/forward.h> +#include <__utility/priority_tag.h> +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANGES) + +namespace ranges::views { + +namespace __drop { + + template struct __is_iota_view : false_type {}; + template struct __is_iota_view> : true_type {}; + + template struct __is_string_view : false_type {}; + template struct __is_string_view> : true_type {}; + + template struct __is_subrange : false_type {}; + template struct __is_subrange> : true_type {}; + + template struct __is_subrange_without_storesize : false_type {}; + template struct __is_subrange> : bool_constant> {}; + + struct __fn : __range_adaptor_closure<__fn> { + + template + requires __is_subrange_without_storesize<_Result>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __make_result(_It __first, _Dp __n, type_identity_t<_Dp> __count, _Sent __last) + noexcept(noexcept(_Result(__first + _VSTD::min(__n, __count), __last, _VSTD::__to_unsigned_like(__n - std::min(__n, __count))))) + -> decltype( _Result(__first + _VSTD::min(__n, __count), __last, _VSTD::__to_unsigned_like(__n - std::min(__n, __count)))) + { return _Result(__first + _VSTD::min(__n, __count), __last, _VSTD::__to_unsigned_like(__n - std::min(__n, __count))); } + + template + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __make_result(_It __first, _Dp __n, type_identity_t<_Dp> __count, _Sent __last) + noexcept(noexcept(_Result(__first + _VSTD::min(__n, __count), __last))) + -> decltype( _Result(__first + _VSTD::min(__n, __count), __last)) + { return _Result(__first + _VSTD::min(__n, __count), __last); } + + template + requires __is_empty_view>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr decay_t<_Rp> __go(_Rp&& __r, _Count&&) noexcept { + return _VSTD::forward<_Rp>(__r); + } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_std_span>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result::element_type>>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)))) + -> decltype( __make_result::element_type>>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r))) + { return __make_result::element_type>>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)); } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_string_view>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)))) + -> decltype( __make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r))) + { return __make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)); } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_iota_view>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)))) + -> decltype( __make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r))) + { return __make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)); } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_subrange>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)))) + -> decltype( __make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r))) + { return __make_result>(ranges::begin(__r), ranges::distance(__r), __count, ranges::end(__r)); } + + template + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(ranges::drop_view(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)))) + -> decltype( ranges::drop_view(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count))) + { return ranges::drop_view(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)); } + + template> _Count> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Rp&& __r, _Count&& __count) const + noexcept(noexcept(__go(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)))) + -> decltype( __go(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count))) + { return __go(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)); } + + template + requires constructible_from, _Count> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Count&& __count) const + noexcept(is_nothrow_constructible_v, _Count>) + { return __range_adaptor_closure_t(_VSTD::__bind_back(*this, _VSTD::forward<_Count>(__count))); } + }; + +} // namespace __drop + +inline namespace __cpo { + inline constexpr auto drop = __drop::__fn{}; +} // namespace __cpo + +} // namespace ranges::views + +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANGES_DROP_H diff --git a/libcxx/include/__ranges/empty_view.h b/libcxx/include/__ranges/empty_view.h --- a/libcxx/include/__ranges/empty_view.h +++ b/libcxx/include/__ranges/empty_view.h @@ -32,6 +32,10 @@ _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 0; } _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return true; } }; + + template struct __is_empty_view : false_type {}; + template struct __is_empty_view> : true_type {}; + } // namespace ranges #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/libcxx/include/__ranges/join_view.h b/libcxx/include/__ranges/join_view.h --- a/libcxx/include/__ranges/join_view.h +++ b/libcxx/include/__ranges/join_view.h @@ -11,6 +11,7 @@ #include <__config> #include <__iterator/concepts.h> +#include <__iterator/indirectly_swappable.h> #include <__iterator/iterator_traits.h> #include <__ranges/access.h> #include <__ranges/all.h> diff --git a/libcxx/include/__ranges/take.h b/libcxx/include/__ranges/take.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__ranges/take.h @@ -0,0 +1,147 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP___RANGES_TAKE_H +#define _LIBCPP___RANGES_TAKE_H + +#include <__algorithm/min.h> +#include <__concepts/constructible.h> +#include <__config> +#include <__functional/bind_back.h> +#include <__iterator/ranges_distance.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/empty_view.h> +#include <__ranges/iota_view.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/subrange.h> +#include <__ranges/take_view.h> +#include <__utility/forward.h> +#include <__utility/priority_tag.h> +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANGES) + +namespace ranges::views { + +namespace __take { + + template struct __is_iota_view : false_type {}; + template struct __is_iota_view> : true_type {}; + + template struct __is_string_view : false_type {}; + template struct __is_string_view> : true_type {}; + + template struct __is_subrange : false_type {}; + template struct __is_subrange> : true_type {}; + + struct __fn : __range_adaptor_closure<__fn> { + + template + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __make_iota_view(_It __first, _Dp __n, type_identity_t<_Dp> __count) + noexcept(noexcept(ranges::iota_view(*__first, *(__first + _VSTD::min(__n, __count))))) + -> decltype( ranges::iota_view(*__first, *(__first + _VSTD::min(__n, __count)))) + { return ranges::iota_view(*__first, *(__first + _VSTD::min(__n, __count))); } + + template + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __make_result(_It __first, _Dp __n, type_identity_t<_Dp> __count) + noexcept(noexcept(_Result(__first, __first + _VSTD::min(__n, __count)))) + -> decltype( _Result(__first, __first + _VSTD::min(__n, __count))) + { return _Result(__first, __first + _VSTD::min(__n, __count)); } + + template + requires __is_empty_view>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr decay_t<_Rp> __go(_Rp&& __r, _Count&&) noexcept { + return _VSTD::forward<_Rp>(__r); + } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_std_span>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result::element_type>>(ranges::begin(__r), ranges::distance(__r), __count))) + -> decltype( __make_result::element_type>>(ranges::begin(__r), ranges::distance(__r), __count)) + { return __make_result::element_type>>(ranges::begin(__r), ranges::distance(__r), __count); } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_string_view>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result>(ranges::begin(__r), ranges::distance(__r), __count))) + -> decltype( __make_result>(ranges::begin(__r), ranges::distance(__r), __count)) + { return __make_result>(ranges::begin(__r), ranges::distance(__r), __count); } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_subrange>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_result>>>(ranges::begin(__r), ranges::distance(__r), __count))) + -> decltype( __make_result>>>(ranges::begin(__r), ranges::distance(__r), __count)) + { return __make_result>>>(ranges::begin(__r), ranges::distance(__r), __count); } + + template + requires random_access_range<_Rp> && sized_range<_Rp> && __is_iota_view>::value + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(__make_iota_view(ranges::begin(__r), ranges::distance(__r), __count))) + -> decltype( __make_iota_view(ranges::begin(__r), ranges::distance(__r), __count)) + { return __make_iota_view(ranges::begin(__r), ranges::distance(__r), __count); } + + template + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_Rp&& __r, _Count&& __count) + noexcept(noexcept(ranges::take_view(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)))) + -> decltype( ranges::take_view(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count))) + { return ranges::take_view(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)); } + + template> _Count> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Rp&& __r, _Count&& __count) const + noexcept(noexcept(__go(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)))) + -> decltype( __go(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count))) + { return __go(_VSTD::forward<_Rp>(__r), _VSTD::forward<_Count>(__count)); } + + template + requires constructible_from, _Count> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Count&& __count) const + noexcept(is_nothrow_constructible_v, _Count>) + { return __range_adaptor_closure_t(_VSTD::__bind_back(*this, _VSTD::forward<_Count>(__count))); } + }; + +} // namespace __take + +inline namespace __cpo { + inline constexpr auto take = __take::__fn{}; +} // namespace __cpo + +} // namespace ranges::views + +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANGES_TAKE_H diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -720,6 +720,7 @@ #include <__algorithm/pop_heap.h> #include <__algorithm/prev_permutation.h> #include <__algorithm/push_heap.h> +#include <__algorithm/ranges_equal.h> #include <__algorithm/remove.h> #include <__algorithm/remove_copy.h> #include <__algorithm/remove_copy_if.h> diff --git a/libcxx/include/iterator b/libcxx/include/iterator --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -582,6 +582,7 @@ #include <__functional_base> #include <__iterator/access.h> #include <__iterator/advance.h> +#include <__iterator/algorithm_concepts.h> #include <__iterator/back_insert_iterator.h> #include <__iterator/common_iterator.h> #include <__iterator/concepts.h> @@ -593,6 +594,9 @@ #include <__iterator/erase_if_container.h> #include <__iterator/front_insert_iterator.h> #include <__iterator/incrementable_traits.h> +#include <__iterator/indirectly_copyable.h> +#include <__iterator/indirectly_movable.h> +#include <__iterator/indirectly_swappable.h> #include <__iterator/insert_iterator.h> #include <__iterator/istreambuf_iterator.h> #include <__iterator/istream_iterator.h> @@ -606,6 +610,7 @@ #include <__iterator/ostream_iterator.h> #include <__iterator/prev.h> #include <__iterator/projected.h> +#include <__iterator/ranges_distance.h> #include <__iterator/readable_traits.h> #include <__iterator/reverse_access.h> #include <__iterator/reverse_iterator.h> diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -279,6 +279,7 @@ module pop_heap { private header "__algorithm/pop_heap.h" } module prev_permutation { private header "__algorithm/prev_permutation.h" } module push_heap { private header "__algorithm/push_heap.h" } + module ranges_equal { private header "__algorithm/ranges_equal.h" } module remove { private header "__algorithm/remove.h" } module remove_copy { private header "__algorithm/remove_copy.h" } module remove_copy_if { private header "__algorithm/remove_copy_if.h" } @@ -564,6 +565,7 @@ private header "__iterator/advance.h" export __function_like } + module algorithm_concepts { private header "__iterator/algorithm_concepts.h" } module back_insert_iterator { private header "__iterator/back_insert_iterator.h" } module common_iterator { private header "__iterator/common_iterator.h" } module concepts { private header "__iterator/concepts.h" } @@ -575,6 +577,9 @@ module erase_if_container { private header "__iterator/erase_if_container.h" } module front_insert_iterator { private header "__iterator/front_insert_iterator.h" } module incrementable_traits { private header "__iterator/incrementable_traits.h" } + module indirectly_copyable { private header "__iterator/indirectly_copyable.h" } + module indirectly_movable { private header "__iterator/indirectly_movable.h" } + module indirectly_swappable { private header "__iterator/indirectly_swappable.h" } module insert_iterator { private header "__iterator/insert_iterator.h" } module istream_iterator { private header "__iterator/istream_iterator.h" } module istreambuf_iterator { private header "__iterator/istreambuf_iterator.h" } @@ -594,6 +599,7 @@ export __function_like } module projected { private header "__iterator/projected.h" } + module ranges_distance { private header "__iterator/ranges_distance.h" } module readable_traits { private header "__iterator/readable_traits.h" } module reverse_access { private header "__iterator/reverse_access.h" } module reverse_iterator { private header "__iterator/reverse_iterator.h" } @@ -757,6 +763,7 @@ module counted { private header "__ranges/counted.h" } module dangling { private header "__ranges/dangling.h" } module data { private header "__ranges/data.h" } + module drop { private header "__ranges/drop.h" } module drop_view { private header "__ranges/drop_view.h" } module empty { private header "__ranges/empty.h" } module empty_view { private header "__ranges/empty_view.h" } @@ -771,6 +778,7 @@ module size { private header "__ranges/size.h" } module single_view { private header "__ranges/single_view.h" } module subrange { private header "__ranges/subrange.h" } + module take { private header "__ranges/take.h" } module take_view { private header "__ranges/take_view.h" } module transform_view { private header "__ranges/transform_view.h" diff --git a/libcxx/include/ranges b/libcxx/include/ranges --- a/libcxx/include/ranges +++ b/libcxx/include/ranges @@ -206,6 +206,7 @@ #include <__ranges/counted.h> #include <__ranges/dangling.h> #include <__ranges/data.h> +#include <__ranges/drop.h> #include <__ranges/drop_view.h> #include <__ranges/empty_view.h> #include <__ranges/empty.h> @@ -218,6 +219,7 @@ #include <__ranges/single_view.h> #include <__ranges/size.h> #include <__ranges/subrange.h> +#include <__ranges/take.h> #include <__ranges/take_view.h> #include <__ranges/transform_view.h> #include <__ranges/view_interface.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/algorithm/ranges_equal.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/algorithm/ranges_equal.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/algorithm/ranges_equal.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__algorithm/ranges_equal.h'}} +#include <__algorithm/ranges_equal.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/iterator/algorithm_concepts.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/algorithm_concepts.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/algorithm_concepts.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__iterator/algorithm_concepts.h'}} +#include <__iterator/algorithm_concepts.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_copyable.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_copyable.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_copyable.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__iterator/indirectly_copyable.h'}} +#include <__iterator/indirectly_copyable.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_movable.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_movable.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_movable.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__iterator/indirectly_movable.h'}} +#include <__iterator/indirectly_movable.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_swappable.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_swappable.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/indirectly_swappable.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__iterator/indirectly_swappable.h'}} +#include <__iterator/indirectly_swappable.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/iterator/ranges_distance.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/ranges_distance.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/iterator/ranges_distance.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__iterator/ranges_distance.h'}} +#include <__iterator/ranges_distance.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/ranges/drop.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/ranges/drop.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/ranges/drop.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__ranges/drop.h'}} +#include <__ranges/drop.h> diff --git a/libcxx/test/libcxx/diagnostics/detail.headers/ranges/take.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/ranges/take.module.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/detail.headers/ranges/take.module.verify.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: modules-build + +// WARNING: This test was generated by 'generate_private_header_tests.py' +// and should not be edited manually. + +// expected-error@*:* {{use of private header from outside its module: '__ranges/take.h'}} +#include <__ranges/take.h> diff --git a/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.copy/indirectly_copyable.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.copy/indirectly_copyable.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.copy/indirectly_copyable.compile.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept indirectly_movable; + +#include + +#include "test_macros.h" +#include "MoveOnly.h" + +struct IndirectlyMovableFromIntPtr { + struct AssignableFromIntRvalue { + AssignableFromIntRvalue& operator=(int&&); + }; + AssignableFromIntRvalue& operator*() const; +}; + +struct IndirectlyCopyableFromLvaluesOnly { + struct AssignableFromIntLvalue { + AssignableFromIntLvalue& operator=(int&); + }; + AssignableFromIntLvalue& operator*() const; +}; +static_assert(!std::indirectly_movable); + +struct IndirectlyCopyableFromIntPtr { + struct AssignableFromInt { + AssignableFromInt& operator=(int); + }; + AssignableFromInt& operator*() const; +}; + +static_assert( std::indirectly_copyable); +static_assert( std::indirectly_copyable); +static_assert(!std::indirectly_copyable); +static_assert(!std::indirectly_copyable); +static_assert(!std::indirectly_copyable); +static_assert(!std::indirectly_copyable); +static_assert(!std::indirectly_copyable); +static_assert( std::indirectly_copyable); +static_assert( std::indirectly_copyable); +static_assert( std::indirectly_copyable); +static_assert(!std::indirectly_copyable); +static_assert(!std::indirectly_copyable); diff --git a/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.copy/indirectly_copyable.subsumption.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.copy/indirectly_copyable.subsumption.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.copy/indirectly_copyable.subsumption.compile.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept indirectly_copyable; + +#include + +template +constexpr bool indirectly_copyable_subsumption() { + return false; +} + +template> O> +constexpr bool indirectly_copyable_subsumption() { + return false; +} + +template + requires std::indirectly_copyable +constexpr bool indirectly_copyable_subsumption() { + return true; +} + +static_assert(indirectly_copyable_subsumption()); diff --git a/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.move/indirectly_movable.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.move/indirectly_movable.compile.pass.cpp --- a/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.move/indirectly_movable.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.requirements/alg.req.ind.move/indirectly_movable.compile.pass.cpp @@ -15,44 +15,24 @@ #include #include "test_macros.h" +#include "MoveOnly.h" -struct IndirectlyMovableWithInt { - int& operator*() const; -}; - -struct Empty {}; - -struct MoveOnly { - MoveOnly(MoveOnly&&) = default; - MoveOnly(MoveOnly const&) = delete; - MoveOnly& operator=(MoveOnly&&) = default; - MoveOnly& operator=(MoveOnly const&) = delete; - MoveOnly() = default; -}; - -template -struct PointerTo { - using value_type = T; - T& operator*() const; +struct IndirectlyMovableFromIntPtr { + struct AssignableFromIntRvalue { + AssignableFromIntRvalue& operator=(int&&); + }; + AssignableFromIntRvalue& operator*() const; }; static_assert( std::indirectly_movable); -static_assert( std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert( std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert( std::indirectly_movable); -static_assert( std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert( std::indirectly_movable); +static_assert( std::indirectly_movable); +static_assert(!std::indirectly_movable); +static_assert(!std::indirectly_movable); static_assert( std::indirectly_movable); +static_assert(!std::indirectly_movable); static_assert(!std::indirectly_movable); static_assert(!std::indirectly_movable); -static_assert(!std::indirectly_movable); -static_assert( std::indirectly_movable, PointerTo>); -static_assert( std::indirectly_movable>); +static_assert( std::indirectly_movable); +static_assert(!std::indirectly_movable); +static_assert(!std::indirectly_movable); +static_assert(!std::indirectly_movable);