[libcxx-commits] [libcxx] [libc++] `std::ranges::advance`: avoid unneeded bounds checks when advancing iterator (PR #84126)
Konstantin Varlamov via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 26 21:17:08 PDT 2024
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/84126 at github.com>
================
@@ -42,6 +42,13 @@ constexpr void check_forward(int* first, int* last, std::iter_difference_t<It> n
// regardless of the iterator category.
assert(it.stride_count() == M);
assert(it.stride_displacement() == M);
+ if (n == 0) {
+ assert(it.equals_count() == 0);
+ } else {
+ assert(it.equals_count() > 0);
+ assert(it.equals_count() == M || it.equals_count() == M + 1);
----------------
var-const wrote:
Thanks for explaining! In that case, we should either pass the expected number of comparisons as a parameter to this function, or pass a boolean parameter to indicate whether we expect the algorithm to hit the sentinel or not. Test cases should be simple so that we can be sure exactly what we're testing.
https://github.com/llvm/llvm-project/pull/84126
More information about the libcxx-commits
mailing list