[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
Mon Apr 1 16:52:43 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>,
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>,
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,18 @@ 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) {
----------------
var-const wrote:

I like this better -- IMO placing this logic where the test case is being set up is more natural, and also this is consistent with how `expected` is calculated. It could probably be refactored further but I think we'll be hitting a point of diminishing returns.

https://github.com/llvm/llvm-project/pull/84126


More information about the libcxx-commits mailing list