xref: /freebsd/contrib/llvm-project/libcxx/include/__ranges/all.h (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
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 <__iterator/concepts.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__ranges/access.h>
17 #include <__ranges/concepts.h>
18 #include <__ranges/owning_view.h>
19 #include <__ranges/range_adaptor.h>
20 #include <__ranges/ref_view.h>
21 #include <__utility/auto_cast.h>
22 #include <__utility/declval.h>
23 #include <__utility/forward.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 _LIBCPP_STD_VER > 17
33 
34 namespace ranges::views {
35 
36 namespace __all {
37   struct __fn : __range_adaptor_closure<__fn> {
38     template<class _Tp>
39       requires ranges::view<decay_t<_Tp>>
40     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
41     constexpr auto operator()(_Tp&& __t) const
42       noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))))
43       -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))
44     {
45       return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
46     }
47 
48     template<class _Tp>
49       requires (!ranges::view<decay_t<_Tp>>) &&
50                requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; }
51     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
52     constexpr auto operator()(_Tp&& __t) const
53       noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)}))
54     {
55       return ranges::ref_view{std::forward<_Tp>(__t)};
56     }
57 
58     template<class _Tp>
59       requires (!ranges::view<decay_t<_Tp>> &&
60                 !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } &&
61                  requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; })
62     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
63     constexpr auto operator()(_Tp&& __t) const
64       noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)}))
65     {
66       return ranges::owning_view{std::forward<_Tp>(__t)};
67     }
68   };
69 } // namespace __all
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(std::declval<_Range>()));
77 
78 } // namespace ranges::views
79 
80 #endif // _LIBCPP_STD_VER > 17
81 
82 _LIBCPP_END_NAMESPACE_STD
83 
84 #endif // _LIBCPP___RANGES_ALL_H
85