[libcxx][ranges] Add `random_access_{iterator,range}`.
Differential Revision: https://reviews.llvm.org/D101316
NOKEYCHECK=True
GitOrigin-RevId: 6ffc41b014f304a76f9a7eab39c122e0a9d7fcb8
diff --git a/include/__iterator/concepts.h b/include/__iterator/concepts.h
index c83fd92..0dd8a72 100644
--- a/include/__iterator/concepts.h
+++ b/include/__iterator/concepts.h
@@ -137,7 +137,22 @@
{ __i-- } -> same_as<_Ip>;
};
- // clang-format on
+template<class _Ip>
+concept random_access_iterator =
+ bidirectional_iterator<_Ip> &&
+ derived_from<_ITER_CONCEPT<_Ip>, random_access_iterator_tag> &&
+ totally_ordered<_Ip> &&
+ sized_sentinel_for<_Ip, _Ip> &&
+ requires(_Ip __i, const _Ip __j, const iter_difference_t<_Ip> __n) {
+ { __i += __n } -> same_as<_Ip&>;
+ { __j + __n } -> same_as<_Ip>;
+ { __n + __j } -> same_as<_Ip>;
+ { __i -= __n } -> same_as<_Ip&>;
+ { __j - __n } -> same_as<_Ip>;
+ { __j[__n] } -> same_as<iter_reference_t<_Ip>>;
+ };
+
+// clang-format on
#endif // !defined(_LIBCPP_HAS_NO_RANGES)
diff --git a/include/__ranges/concepts.h b/include/__ranges/concepts.h
index 578b153..8c28df3 100644
--- a/include/__ranges/concepts.h
+++ b/include/__ranges/concepts.h
@@ -62,6 +62,10 @@
template <class _Tp>
concept common_range = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp> >;
+
+ template <class _Tp>
+ concept random_access_range =
+ bidirectional_range<_Tp> && random_access_iterator<iterator_t<_Tp> >;
} // namespace ranges
#endif // !defined(_LIBCPP_HAS_NO_RANGES)
diff --git a/include/iterator b/include/iterator
index 97677fe..ad98d8c 100644
--- a/include/iterator
+++ b/include/iterator
@@ -87,6 +87,10 @@
template<class I>
concept bidirectional_iterator = see below; // since C++20
+// [iterator.concept.random.access], concept random_access_iterator
+template<class I>
+ concept random_access_iterator = see below; // since C++20
+
template<class Category, class T, class Distance = ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator