[libcxx-commits] [libcxx] 084cb22 - [libc++][ranges][enumerate_view] Update iterator `iter_move` test (#219474)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 1 01:18:22 PDT 2026
Author: Lucas Mellone
Date: 2026-09-01T11:18:18+03:00
New Revision: 084cb22437448bc53228f7f03dc20749dabe96a6
URL: https://github.com/llvm/llvm-project/commit/084cb22437448bc53228f7f03dc20749dabe96a6
DIFF: https://github.com/llvm/llvm-project/commit/084cb22437448bc53228f7f03dc20749dabe96a6.diff
LOG: [libc++][ranges][enumerate_view] Update iterator `iter_move` test (#219474)
Completes the [range.enumerate.iterator] `iter_move` test by addressing
the review comment
https://github.com/llvm/llvm-project/pull/73617#discussion_r1416642892
from the original implementation.
---------
Co-authored-by: Hristo Hristov <zingam at outlook.com>
Co-authored-by: Hristo Hristov <hghristov.rmm at gmail.com>
Co-authored-by: A. Jiang <de34 at live.cn>
Added:
Modified:
libcxx/test/std/ranges/range.adaptors/range.enumerate/iterator/iter_move.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/ranges/range.adaptors/range.enumerate/iterator/iter_move.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.enumerate/iterator/iter_move.pass.cpp
index ed28662a8a5eb..b5c9209be162e 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.enumerate/iterator/iter_move.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.enumerate/iterator/iter_move.pass.cpp
@@ -28,6 +28,12 @@
#include "test_iterators.h"
#include "../types.h"
+#include "../../range_adaptor_types.h"
+
+struct ThrowingMove {
+ ThrowingMove() = default;
+ ThrowingMove(ThrowingMove&&) {}
+};
template <class Iterator, bool HasNoexceptIterMove>
constexpr void test() {
@@ -38,22 +44,49 @@ constexpr void test() {
std::array array{0, 1, 2, 3, 4};
- View mv{Iterator(std::to_address(base(array.begin()))), Sentinel(Iterator(std::to_address(base(array.end()))))};
- EnumerateView ev{std::move(mv)};
- EnumerateIterator const it = ev.begin();
-
- auto&& result = iter_move(it);
-
- using DifferenceT = std::iter_
diff erence_t<EnumerateIterator>;
- static_assert(std::is_same_v<decltype(result), std::tuple<DifferenceT, int&&>&&>);
-
- assert(get<0>(result) == 0);
- assert(&get<1>(result) == std::to_address(base(array.begin())));
-
- static_assert(noexcept(iter_move(it)) == HasNoexceptIterMove);
+ {
+ // Underlying iter_move may not trow.
+ View mv{Iterator(std::to_address(base(array.begin()))), Sentinel(Iterator(std::to_address(base(array.end()))))};
+ EnumerateView ev{std::move(mv)};
+ EnumerateIterator const it = ev.begin();
+
+ auto&& result = iter_move(it);
+
+ using DifferenceT = std::iter_
diff erence_t<EnumerateIterator>;
+ static_assert(std::is_same_v<decltype(result), std::tuple<DifferenceT, int&&>&&>);
+
+ assert(get<0>(result) == 0);
+ assert(&get<1>(result) == std::to_address(base(array.begin())));
+
+ static_assert(noexcept(iter_move(it)) == HasNoexceptIterMove);
+ }
+
+ {
+ // !is_nothrow_move_constructible_v<range_rvalue_reference_t<Base>>
+ // underlying iter_move may throw.
+ auto throwingMoveRange =
+ std::views::iota(0, 9) | std::views::transform([](auto) noexcept { return ThrowingMove{}; });
+ std::ranges::enumerate_view v(throwingMoveRange);
+ auto it = v.begin();
+ static_assert(!noexcept(std::ranges::iter_move(it)));
+ }
+
+ {
+ // Underlying iterator iter_move is called through ranges::iter_move.
+ adltest::IterMoveSwapRange r1{};
+ assert(r1.iter_move_called_times == 0);
+ std::ranges::enumerate_view v(r1);
+ auto it = v.begin();
+
+ (void)std::ranges::iter_move(it);
+ assert(r1.iter_move_called_times == 1);
+
+ (void)std::ranges::iter_move(it);
+ assert(r1.iter_move_called_times == 2);
+ }
}
-constexpr bool tests() {
+constexpr bool test() {
// clang-format off
test<cpp17_input_iterator<int*>, /* noexcept */ false>();
test<cpp20_input_iterator<int*>, /* noexcept */ false>();
@@ -70,8 +103,8 @@ constexpr bool tests() {
}
int main(int, char**) {
- tests();
- static_assert(tests());
+ test();
+ static_assert(test());
return 0;
}
More information about the libcxx-commits
mailing list