[Clang] Don't form a type constraint if the concept is invalid (#122065)
[llvm-project.git] / libcxx / include / __cxx03 / __ranges / all.h
blob57497f83478b564696bdd2970660c1f1770ba973
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CXX03___RANGES_ALL_H
11 #define _LIBCPP___CXX03___RANGES_ALL_H
13 #include <__cxx03/__config>
14 #include <__cxx03/__functional/compose.h> // TODO(modules): Those should not be required
15 #include <__cxx03/__functional/perfect_forward.h> //
16 #include <__cxx03/__iterator/concepts.h>
17 #include <__cxx03/__iterator/iterator_traits.h>
18 #include <__cxx03/__ranges/access.h>
19 #include <__cxx03/__ranges/concepts.h>
20 #include <__cxx03/__ranges/owning_view.h>
21 #include <__cxx03/__ranges/range_adaptor.h>
22 #include <__cxx03/__ranges/ref_view.h>
23 #include <__cxx03/__type_traits/decay.h>
24 #include <__cxx03/__utility/auto_cast.h>
25 #include <__cxx03/__utility/declval.h>
26 #include <__cxx03/__utility/forward.h>
28 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29 # pragma GCC system_header
30 #endif
32 _LIBCPP_BEGIN_NAMESPACE_STD
34 #if _LIBCPP_STD_VER >= 20
36 namespace ranges::views {
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 constexpr auto operator()(_Tp&& __t) const noexcept(
43 noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))) -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))) {
44 return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
47 template <class _Tp>
48 requires(!ranges::view<decay_t<_Tp>>) && requires(_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; }
49 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
50 noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)})) {
51 return ranges::ref_view{std::forward<_Tp>(__t)};
54 template <class _Tp>
55 requires(
56 !ranges::view<decay_t<_Tp>> && !requires(_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } &&
57 requires(_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; })
58 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
59 noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)})) {
60 return ranges::owning_view{std::forward<_Tp>(__t)};
63 } // namespace __all
65 inline namespace __cpo {
66 inline constexpr auto all = __all::__fn{};
67 } // namespace __cpo
69 template <ranges::viewable_range _Range>
70 using all_t = decltype(views::all(std::declval<_Range>()));
72 } // namespace ranges::views
74 #endif // _LIBCPP_STD_VER >= 20
76 _LIBCPP_END_NAMESPACE_STD
78 #endif // _LIBCPP___CXX03___RANGES_ALL_H