xref: /freebsd/contrib/llvm-project/libcxx/include/__ranges/all.h (revision 1fd87a682ad7442327078e1eeb63edc4258f9815)
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 //===----------------------------------------------------------------------===//
9fe6060f1SDimitry Andric #ifndef _LIBCPP___RANGES_ALL_H
10fe6060f1SDimitry Andric #define _LIBCPP___RANGES_ALL_H
11fe6060f1SDimitry Andric 
12fe6060f1SDimitry Andric #include <__config>
13fe6060f1SDimitry Andric #include <__iterator/concepts.h>
14fe6060f1SDimitry Andric #include <__iterator/iterator_traits.h>
15fe6060f1SDimitry Andric #include <__ranges/access.h>
16fe6060f1SDimitry Andric #include <__ranges/concepts.h>
1704eeddc0SDimitry Andric #include <__ranges/owning_view.h>
18349cc55cSDimitry Andric #include <__ranges/range_adaptor.h>
19fe6060f1SDimitry Andric #include <__ranges/ref_view.h>
200eae32dcSDimitry Andric #include <__utility/auto_cast.h>
21fe6060f1SDimitry Andric #include <__utility/declval.h>
22fe6060f1SDimitry Andric #include <__utility/forward.h>
23fe6060f1SDimitry Andric #include <type_traits>
24fe6060f1SDimitry Andric 
25fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26fe6060f1SDimitry Andric #pragma GCC system_header
27fe6060f1SDimitry Andric #endif
28fe6060f1SDimitry Andric 
29fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
30fe6060f1SDimitry Andric 
31*1fd87a68SDimitry Andric #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
32fe6060f1SDimitry Andric 
33349cc55cSDimitry Andric namespace ranges::views {
34fe6060f1SDimitry Andric 
35fe6060f1SDimitry Andric namespace __all {
36349cc55cSDimitry Andric   struct __fn : __range_adaptor_closure<__fn> {
37fe6060f1SDimitry Andric     template<class _Tp>
38fe6060f1SDimitry Andric       requires ranges::view<decay_t<_Tp>>
39349cc55cSDimitry Andric     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
40fe6060f1SDimitry Andric     constexpr auto operator()(_Tp&& __t) const
410eae32dcSDimitry Andric       noexcept(noexcept(_LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t))))
42fe6060f1SDimitry Andric     {
430eae32dcSDimitry Andric       return _LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t));
44fe6060f1SDimitry Andric     }
45fe6060f1SDimitry Andric 
46fe6060f1SDimitry Andric     template<class _Tp>
47fe6060f1SDimitry Andric       requires (!ranges::view<decay_t<_Tp>>) &&
48fe6060f1SDimitry Andric                requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; }
49349cc55cSDimitry Andric     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
50fe6060f1SDimitry Andric     constexpr auto operator()(_Tp&& __t) const
51fe6060f1SDimitry Andric       noexcept(noexcept(ranges::ref_view{_VSTD::forward<_Tp>(__t)}))
52fe6060f1SDimitry Andric     {
53fe6060f1SDimitry Andric       return ranges::ref_view{_VSTD::forward<_Tp>(__t)};
54fe6060f1SDimitry Andric     }
55fe6060f1SDimitry Andric 
56fe6060f1SDimitry Andric     template<class _Tp>
57fe6060f1SDimitry Andric       requires (!ranges::view<decay_t<_Tp>> &&
58fe6060f1SDimitry Andric                 !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } &&
5904eeddc0SDimitry Andric                  requires (_Tp&& __t) { ranges::owning_view{_VSTD::forward<_Tp>(__t)}; })
60349cc55cSDimitry Andric     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
61fe6060f1SDimitry Andric     constexpr auto operator()(_Tp&& __t) const
6204eeddc0SDimitry Andric       noexcept(noexcept(ranges::owning_view{_VSTD::forward<_Tp>(__t)}))
63fe6060f1SDimitry Andric     {
6404eeddc0SDimitry Andric       return ranges::owning_view{_VSTD::forward<_Tp>(__t)};
65fe6060f1SDimitry Andric     }
66fe6060f1SDimitry Andric   };
67*1fd87a68SDimitry Andric } // namespace __all
68fe6060f1SDimitry Andric 
69fe6060f1SDimitry Andric inline namespace __cpo {
70fe6060f1SDimitry Andric   inline constexpr auto all = __all::__fn{};
71fe6060f1SDimitry Andric } // namespace __cpo
72fe6060f1SDimitry Andric 
73fe6060f1SDimitry Andric template<ranges::viewable_range _Range>
74fe6060f1SDimitry Andric using all_t = decltype(views::all(declval<_Range>()));
75fe6060f1SDimitry Andric 
76349cc55cSDimitry Andric } // namespace ranges::views
77fe6060f1SDimitry Andric 
78*1fd87a68SDimitry Andric #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
79fe6060f1SDimitry Andric 
80fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
81fe6060f1SDimitry Andric 
82fe6060f1SDimitry Andric #endif // _LIBCPP___RANGES_ALL_H
83