all.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <__iterator/concepts.h>
  13. #include <__iterator/iterator_traits.h>
  14. #include <__ranges/access.h>
  15. #include <__ranges/concepts.h>
  16. #include <__ranges/owning_view.h>
  17. #include <__ranges/range_adaptor.h>
  18. #include <__ranges/ref_view.h>
  19. #include <__utility/auto_cast.h>
  20. #include <__utility/declval.h>
  21. #include <__utility/forward.h>
  22. #include <type_traits>
  23. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  24. # pragma GCC system_header
  25. #endif
  26. _LIBCPP_BEGIN_NAMESPACE_STD
  27. #if _LIBCPP_STD_VER > 17
  28. namespace ranges::views {
  29. namespace __all {
  30. struct __fn : __range_adaptor_closure<__fn> {
  31. template<class _Tp>
  32. requires ranges::view<decay_t<_Tp>>
  33. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  34. constexpr auto operator()(_Tp&& __t) const
  35. noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))))
  36. -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))
  37. {
  38. return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
  39. }
  40. template<class _Tp>
  41. requires (!ranges::view<decay_t<_Tp>>) &&
  42. requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; }
  43. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  44. constexpr auto operator()(_Tp&& __t) const
  45. noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)}))
  46. {
  47. return ranges::ref_view{std::forward<_Tp>(__t)};
  48. }
  49. template<class _Tp>
  50. requires (!ranges::view<decay_t<_Tp>> &&
  51. !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } &&
  52. requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; })
  53. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  54. constexpr auto operator()(_Tp&& __t) const
  55. noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)}))
  56. {
  57. return ranges::owning_view{std::forward<_Tp>(__t)};
  58. }
  59. };
  60. } // namespace __all
  61. inline namespace __cpo {
  62. inline constexpr auto all = __all::__fn{};
  63. } // namespace __cpo
  64. template<ranges::viewable_range _Range>
  65. using all_t = decltype(views::all(std::declval<_Range>()));
  66. } // namespace ranges::views
  67. #endif // _LIBCPP_STD_VER > 17
  68. _LIBCPP_END_NAMESPACE_STD
  69. #endif // _LIBCPP___RANGES_ALL_H