all.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <__config>
  12. #include <__functional/compose.h> // TODO(modules): Those should not be required
  13. #include <__functional/perfect_forward.h> //
  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 <__type_traits/decay.h>
  22. #include <__utility/auto_cast.h>
  23. #include <__utility/declval.h>
  24. #include <__utility/forward.h>
  25. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  26. # pragma GCC system_header
  27. #endif
  28. _LIBCPP_BEGIN_NAMESPACE_STD
  29. #if _LIBCPP_STD_VER >= 20
  30. namespace ranges::views {
  31. namespace __all {
  32. struct __fn : __range_adaptor_closure<__fn> {
  33. template<class _Tp>
  34. requires ranges::view<decay_t<_Tp>>
  35. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  36. constexpr auto operator()(_Tp&& __t) const
  37. noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))))
  38. -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))
  39. {
  40. return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
  41. }
  42. template<class _Tp>
  43. requires (!ranges::view<decay_t<_Tp>>) &&
  44. requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; }
  45. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  46. constexpr auto operator()(_Tp&& __t) const
  47. noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)}))
  48. {
  49. return ranges::ref_view{std::forward<_Tp>(__t)};
  50. }
  51. template<class _Tp>
  52. requires (!ranges::view<decay_t<_Tp>> &&
  53. !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } &&
  54. requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; })
  55. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  56. constexpr auto operator()(_Tp&& __t) const
  57. noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)}))
  58. {
  59. return ranges::owning_view{std::forward<_Tp>(__t)};
  60. }
  61. };
  62. } // namespace __all
  63. inline namespace __cpo {
  64. inline constexpr auto all = __all::__fn{};
  65. } // namespace __cpo
  66. template<ranges::viewable_range _Range>
  67. using all_t = decltype(views::all(std::declval<_Range>()));
  68. } // namespace ranges::views
  69. #endif // _LIBCPP_STD_VER >= 20
  70. _LIBCPP_END_NAMESPACE_STD
  71. #endif // _LIBCPP___RANGES_ALL_H