[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
Sun Mar 31 16:24:57 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>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/84126 at github.com>


================
@@ -76,7 +88,11 @@ constexpr void check_forward_sized_sentinel(int* first, int* last, std::iter_dif
 
 template <typename It>
 constexpr void check_backward(int* first, int* last, std::iter_difference_t<It> n, int* expected) {
-  static_assert(std::random_access_iterator<It>, "This test doesn't support non random access iterators");
+  // Check preconditions for `advance` when called with negative `n`:
+  // <https://eel.is/c++draft/iterators#range.iter.op.advance-5>
----------------
var-const wrote:

Unfortunately, while these links are super useful now, they may become stale. Consider removing them or just leaving the name of the section for easier reference (`[range.iter.op.advance]`).

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


More information about the libcxx-commits mailing list