[libc++][ranges] iterator.concept.sizedsentinel: sized_sentinel_for and disable_sized_sentinel_for.
Based on D100160.
Reviewed By: cjdb, ldionne, Quuxplusone, #libc, miscco
Differential Revision: https://reviews.llvm.org/D100587
GitOrigin-RevId: bdd68357901d2ccdd110cf35746703ac8e46de3c
diff --git a/include/__iterator/concepts.h b/include/__iterator/concepts.h
index 3a9b628..445a88f 100644
--- a/include/__iterator/concepts.h
+++ b/include/__iterator/concepts.h
@@ -99,6 +99,18 @@
input_or_output_iterator<_Ip> &&
__weakly_equality_comparable_with<_Sp, _Ip>;
+template<class, class>
+inline constexpr bool disable_sized_sentinel_for = false;
+
+template<class _Sp, class _Ip>
+concept sized_sentinel_for =
+ sentinel_for<_Sp, _Ip> &&
+ !disable_sized_sentinel_for<remove_cv_t<_Sp>, remove_cv_t<_Ip> > &&
+ requires(const _Ip& __i, const _Sp& __s) {
+ { __s - __i } -> same_as<iter_difference_t<_Ip> >;
+ { __i - __s } -> same_as<iter_difference_t<_Ip> >;
+ };
+
// clang-format on
#endif // !defined(_LIBCPP_HAS_NO_RANGES)
diff --git a/include/iterator b/include/iterator
index 74d04ce..918c96d 100644
--- a/include/iterator
+++ b/include/iterator
@@ -68,6 +68,13 @@
template<class S, class I>
concept sentinel_for = see below; // since C++20
+// [iterator.concept.sizedsentinel], concept sized_sentinel_for
+template<class S, class I>
+ inline constexpr bool disable_sized_sentinel_for = false;
+
+template<class S, class I>
+ concept sized_sentinel_for = see below;
+
template<class Category, class T, class Distance = ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator
@@ -459,6 +466,7 @@
#include <__iterator/iter_move.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/readable_traits.h>
+#include <__iterator/concepts.h>
#include <__memory/addressof.h>
#include <__memory/pointer_traits.h>
#include <version>