access.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_ACCESS_H
  10. #define _LIBCPP___ITERATOR_ACCESS_H
  11. #include <__config>
  12. #include <cstddef>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. template <class _Tp, size_t _Np>
  18. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  19. _Tp*
  20. begin(_Tp (&__array)[_Np])
  21. {
  22. return __array;
  23. }
  24. template <class _Tp, size_t _Np>
  25. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  26. _Tp*
  27. end(_Tp (&__array)[_Np])
  28. {
  29. return __array + _Np;
  30. }
  31. #if !defined(_LIBCPP_CXX03_LANG)
  32. template <class _Cp>
  33. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  34. auto
  35. begin(_Cp& __c) -> decltype(__c.begin())
  36. {
  37. return __c.begin();
  38. }
  39. template <class _Cp>
  40. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  41. auto
  42. begin(const _Cp& __c) -> decltype(__c.begin())
  43. {
  44. return __c.begin();
  45. }
  46. template <class _Cp>
  47. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  48. auto
  49. end(_Cp& __c) -> decltype(__c.end())
  50. {
  51. return __c.end();
  52. }
  53. template <class _Cp>
  54. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
  55. auto
  56. end(const _Cp& __c) -> decltype(__c.end())
  57. {
  58. return __c.end();
  59. }
  60. #if _LIBCPP_STD_VER >= 14
  61. template <class _Cp>
  62. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  63. auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
  64. {
  65. return _VSTD::begin(__c);
  66. }
  67. template <class _Cp>
  68. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  69. auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
  70. {
  71. return _VSTD::end(__c);
  72. }
  73. #endif
  74. #else // defined(_LIBCPP_CXX03_LANG)
  75. template <class _Cp>
  76. _LIBCPP_INLINE_VISIBILITY
  77. typename _Cp::iterator
  78. begin(_Cp& __c)
  79. {
  80. return __c.begin();
  81. }
  82. template <class _Cp>
  83. _LIBCPP_INLINE_VISIBILITY
  84. typename _Cp::const_iterator
  85. begin(const _Cp& __c)
  86. {
  87. return __c.begin();
  88. }
  89. template <class _Cp>
  90. _LIBCPP_INLINE_VISIBILITY
  91. typename _Cp::iterator
  92. end(_Cp& __c)
  93. {
  94. return __c.end();
  95. }
  96. template <class _Cp>
  97. _LIBCPP_INLINE_VISIBILITY
  98. typename _Cp::const_iterator
  99. end(const _Cp& __c)
  100. {
  101. return __c.end();
  102. }
  103. #endif // !defined(_LIBCPP_CXX03_LANG)
  104. _LIBCPP_END_NAMESPACE_STD
  105. #endif // _LIBCPP___ITERATOR_ACCESS_H