1fe6060f1SDimitry Andric // -*- C++ -*- 2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 3fe6060f1SDimitry Andric // 4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7fe6060f1SDimitry Andric // 8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 9bdd1243dSDimitry Andric 10fe6060f1SDimitry Andric #ifndef _LIBCPP___RANGES_ALL_H 11fe6060f1SDimitry Andric #define _LIBCPP___RANGES_ALL_H 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric #include <__config> 1406c3fb27SDimitry Andric #include <__functional/compose.h> // TODO(modules): Those should not be required 1506c3fb27SDimitry Andric #include <__functional/perfect_forward.h> // 16fe6060f1SDimitry Andric #include <__iterator/concepts.h> 17fe6060f1SDimitry Andric #include <__iterator/iterator_traits.h> 18fe6060f1SDimitry Andric #include <__ranges/access.h> 19fe6060f1SDimitry Andric #include <__ranges/concepts.h> 2004eeddc0SDimitry Andric #include <__ranges/owning_view.h> 21349cc55cSDimitry Andric #include <__ranges/range_adaptor.h> 22fe6060f1SDimitry Andric #include <__ranges/ref_view.h> 2306c3fb27SDimitry Andric #include <__type_traits/decay.h> 240eae32dcSDimitry Andric #include <__utility/auto_cast.h> 25fe6060f1SDimitry Andric #include <__utility/declval.h> 26fe6060f1SDimitry Andric #include <__utility/forward.h> 27fe6060f1SDimitry Andric 28fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 29fe6060f1SDimitry Andric # pragma GCC system_header 30fe6060f1SDimitry Andric #endif 31fe6060f1SDimitry Andric 32fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 33fe6060f1SDimitry Andric 3406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 35fe6060f1SDimitry Andric 36349cc55cSDimitry Andric namespace ranges::views { 37fe6060f1SDimitry Andric 38fe6060f1SDimitry Andric namespace __all { 39349cc55cSDimitry Andric struct __fn : __range_adaptor_closure<__fn> { 40fe6060f1SDimitry Andric template <class _Tp> 41fe6060f1SDimitry Andric requires ranges::view<decay_t<_Tp>> 42*cb14a3feSDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const 4381ad6265SDimitry Andric noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))) 44*cb14a3feSDimitry Andric -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))) { 4581ad6265SDimitry Andric return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)); 46fe6060f1SDimitry Andric } 47fe6060f1SDimitry Andric 48fe6060f1SDimitry Andric template <class _Tp> 49*cb14a3feSDimitry Andric requires(!ranges::view<decay_t<_Tp>>) && requires(_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } 50*cb14a3feSDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const 51*cb14a3feSDimitry Andric noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)})) { 5281ad6265SDimitry Andric return ranges::ref_view{std::forward<_Tp>(__t)}; 53fe6060f1SDimitry Andric } 54fe6060f1SDimitry Andric 55fe6060f1SDimitry Andric template <class _Tp> 56*cb14a3feSDimitry Andric requires( 57*cb14a3feSDimitry Andric !ranges::view<decay_t<_Tp>> && !requires(_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } && 5881ad6265SDimitry Andric requires(_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; }) 59*cb14a3feSDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const 60*cb14a3feSDimitry Andric noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)})) { 6181ad6265SDimitry Andric return ranges::owning_view{std::forward<_Tp>(__t)}; 62fe6060f1SDimitry Andric } 63fe6060f1SDimitry Andric }; 641fd87a68SDimitry Andric } // namespace __all 65fe6060f1SDimitry Andric 66fe6060f1SDimitry Andric inline namespace __cpo { 67fe6060f1SDimitry Andric inline constexpr auto all = __all::__fn{}; 68fe6060f1SDimitry Andric } // namespace __cpo 69fe6060f1SDimitry Andric 70fe6060f1SDimitry Andric template <ranges::viewable_range _Range> 71bdd1243dSDimitry Andric using all_t = decltype(views::all(std::declval<_Range>())); 72fe6060f1SDimitry Andric 73349cc55cSDimitry Andric } // namespace ranges::views 74fe6060f1SDimitry Andric 7506c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 76fe6060f1SDimitry Andric 77fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD 78fe6060f1SDimitry Andric 79fe6060f1SDimitry Andric #endif // _LIBCPP___RANGES_ALL_H 80