Skip to content

Commit d0521d4

Browse files
test iterator iter move
1 parent fc4f7e5 commit d0521d4

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/iter_move.pass.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,39 @@ struct Range : std::ranges::view_base {
2929
int* end_;
3030
};
3131

32+
struct ThrowingMove {
33+
ThrowingMove() = default;
34+
ThrowingMove(ThrowingMove&&) {}
35+
};
36+
3237
template <class Iterator, bool HasNoexceptIterMove>
3338
constexpr bool test() {
3439
using Sentinel = sentinel_wrapper<Iterator>;
3540
using View = minimal_view<Iterator, Sentinel>;
36-
using ConcatView = std::ranges::concat_view<View>;
37-
using ConcatIterator = std::ranges::iterator_t<ConcatView>;
38-
39-
auto make_concat_view = [](auto begin, auto end) {
40-
View view{Iterator(begin), Sentinel(Iterator(end))};
41-
return ConcatView(std::move(view));
42-
};
4341

44-
// noexcept in case of a forward iterator
4542
{
46-
int buff[] = {0, 1, 2, 3};
47-
ConcatView view = make_concat_view(buff, buff + 4);
48-
ConcatIterator it = view.begin();
49-
int&& result = iter_move(it);
43+
std::array<int, 5> array1{0, 1, 2, 3, 4};
44+
std::array<int, 5> array2{5, 6, 7, 8, 9};
45+
46+
View v1{Iterator(array1.data()), Sentinel(Iterator(array1.data() + array1.size()))};
47+
View v2{Iterator(array2.data()), Sentinel(Iterator(array2.data() + array2.size()))};
48+
std::ranges::concat_view view(std::move(v1), std::move(v2));
49+
50+
auto it = view.begin();
51+
assert(std::ranges::iter_move(view.begin()) == 0);
5052
static_assert(noexcept(iter_move(it)) == HasNoexceptIterMove);
51-
assert(&result == buff);
5253
}
5354

55+
{
56+
// iter_move may throw
57+
auto throwingMoveRange =
58+
std::views::iota(0, 2) | std::views::transform([](auto) noexcept { return ThrowingMove{}; });
59+
std::ranges::concat_view v(throwingMoveRange);
60+
auto it = v.begin();
61+
static_assert(!noexcept(std::ranges::iter_move(it)));
62+
}
63+
64+
5465
return true;
5566
}
5667

0 commit comments

Comments
 (0)