reverse_access.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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___ITERATOR_REVERSE_ACCESS_H
  10. #define _LIBCPP___ITERATOR_REVERSE_ACCESS_H
  11. #include <__config>
  12. #include <__iterator/reverse_iterator.h>
  13. #include <cstddef>
  14. #include <initializer_list>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. #if _LIBCPP_STD_VER >= 14
  20. template <class _Tp, size_t _Np>
  21. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  22. reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
  23. {
  24. return reverse_iterator<_Tp*>(__array + _Np);
  25. }
  26. template <class _Tp, size_t _Np>
  27. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  28. reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
  29. {
  30. return reverse_iterator<_Tp*>(__array);
  31. }
  32. template <class _Ep>
  33. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  34. reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
  35. {
  36. return reverse_iterator<const _Ep*>(__il.end());
  37. }
  38. template <class _Ep>
  39. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  40. reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
  41. {
  42. return reverse_iterator<const _Ep*>(__il.begin());
  43. }
  44. template <class _Cp>
  45. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  46. auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
  47. {
  48. return __c.rbegin();
  49. }
  50. template <class _Cp>
  51. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  52. auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
  53. {
  54. return __c.rbegin();
  55. }
  56. template <class _Cp>
  57. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  58. auto rend(_Cp& __c) -> decltype(__c.rend())
  59. {
  60. return __c.rend();
  61. }
  62. template <class _Cp>
  63. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  64. auto rend(const _Cp& __c) -> decltype(__c.rend())
  65. {
  66. return __c.rend();
  67. }
  68. template <class _Cp>
  69. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  70. auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
  71. {
  72. return _VSTD::rbegin(__c);
  73. }
  74. template <class _Cp>
  75. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  76. auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
  77. {
  78. return _VSTD::rend(__c);
  79. }
  80. #endif // _LIBCPP_STD_VER >= 14
  81. _LIBCPP_END_NAMESPACE_STD
  82. #endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H