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___RANGES_ALL_H 11 #define _LIBCPP___RANGES_ALL_H 12 13 #include <__config> 14 #include <__functional/compose.h> // TODO(modules): Those should not be required 15 #include <__functional/perfect_forward.h> // 16 #include <__iterator/concepts.h> 17 #include <__iterator/iterator_traits.h> 18 #include <__ranges/access.h> 19 #include <__ranges/concepts.h> 20 #include <__ranges/owning_view.h> 21 #include <__ranges/range_adaptor.h> 22 #include <__ranges/ref_view.h> 23 #include <__type_traits/decay.h> 24 #include <__utility/auto_cast.h> 25 #include <__utility/declval.h> 26 #include <__utility/forward.h> 27 28 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 29 # pragma GCC system_header 30 #endif 31 32 _LIBCPP_BEGIN_NAMESPACE_STD 33 34 #if _LIBCPP_STD_VER >= 20 35 36 namespace ranges::views { 37 38 namespace __all { 39 struct __fn : __range_adaptor_closure<__fn> { 40 template<class _Tp> 41 requires ranges::view<decay_t<_Tp>> 42 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI 43 constexpr auto operator()(_Tp&& __t) const 44 noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))) 45 -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))) 46 { 47 return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)); 48 } 49 50 template<class _Tp> 51 requires (!ranges::view<decay_t<_Tp>>) && 52 requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } 53 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI 54 constexpr auto operator()(_Tp&& __t) const 55 noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)})) 56 { 57 return ranges::ref_view{std::forward<_Tp>(__t)}; 58 } 59 60 template<class _Tp> 61 requires (!ranges::view<decay_t<_Tp>> && 62 !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } && 63 requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; }) 64 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI 65 constexpr auto operator()(_Tp&& __t) const 66 noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)})) 67 { 68 return ranges::owning_view{std::forward<_Tp>(__t)}; 69 } 70 }; 71 } // namespace __all 72 73 inline namespace __cpo { 74 inline constexpr auto all = __all::__fn{}; 75 } // namespace __cpo 76 77 template<ranges::viewable_range _Range> 78 using all_t = decltype(views::all(std::declval<_Range>())); 79 80 } // namespace ranges::views 81 82 #endif // _LIBCPP_STD_VER >= 20 83 84 _LIBCPP_END_NAMESPACE_STD 85 86 #endif // _LIBCPP___RANGES_ALL_H 87