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