xref: /freebsd/contrib/llvm-project/libcxx/include/__ranges/all.h (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
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/owning_view.h>
18 #include <__ranges/range_adaptor.h>
19 #include <__ranges/ref_view.h>
20 #include <__utility/auto_cast.h>
21 #include <__utility/declval.h>
22 #include <__utility/forward.h>
23 #include <type_traits>
24 
25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 #  pragma GCC system_header
27 #endif
28 
29 _LIBCPP_BEGIN_NAMESPACE_STD
30 
31 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32 
33 namespace ranges::views {
34 
35 namespace __all {
36   struct __fn : __range_adaptor_closure<__fn> {
37     template<class _Tp>
38       requires ranges::view<decay_t<_Tp>>
39     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
40     constexpr auto operator()(_Tp&& __t) const
41       noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))))
42       -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))
43     {
44       return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
45     }
46 
47     template<class _Tp>
48       requires (!ranges::view<decay_t<_Tp>>) &&
49                requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; }
50     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
51     constexpr auto operator()(_Tp&& __t) const
52       noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)}))
53     {
54       return ranges::ref_view{std::forward<_Tp>(__t)};
55     }
56 
57     template<class _Tp>
58       requires (!ranges::view<decay_t<_Tp>> &&
59                 !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } &&
60                  requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; })
61     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
62     constexpr auto operator()(_Tp&& __t) const
63       noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)}))
64     {
65       return ranges::owning_view{std::forward<_Tp>(__t)};
66     }
67   };
68 } // namespace __all
69 
70 inline namespace __cpo {
71   inline constexpr auto all = __all::__fn{};
72 } // namespace __cpo
73 
74 template<ranges::viewable_range _Range>
75 using all_t = decltype(views::all(declval<_Range>()));
76 
77 } // namespace ranges::views
78 
79 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80 
81 _LIBCPP_END_NAMESPACE_STD
82 
83 #endif // _LIBCPP___RANGES_ALL_H
84