|
21 | 21 | template <class It> |
22 | 22 | concept has_iter_swap = requires(It it) { std::ranges::iter_swap(it, it); }; |
23 | 23 |
|
| 24 | +struct ThrowingMove { |
| 25 | + ThrowingMove() = default; |
| 26 | + ThrowingMove(ThrowingMove&&) {} |
| 27 | + ThrowingMove& operator=(ThrowingMove&&){return *this;} |
| 28 | +}; |
| 29 | + |
24 | 30 | template <class Iterator, bool IsNoexcept> |
25 | 31 | constexpr void test() { |
26 | 32 | using Sentinel = sentinel_wrapper<Iterator>; |
27 | 33 | using View = minimal_view<Iterator, Sentinel>; |
28 | 34 | using ConcatView = std::ranges::concat_view<View>; |
29 | 35 |
|
30 | | - auto make_concat_view = [](auto begin, auto end) { |
31 | | - View view{Iterator(begin), Sentinel(Iterator(end))}; |
32 | | - return ConcatView(std::move(view)); |
33 | | - }; |
34 | | - |
35 | 36 | { |
36 | | - std::array<int, 5> array{0, 1, 2, 3, 4}; |
37 | | - ConcatView view = make_concat_view(array.data(), array.data() + array.size()); |
38 | | - std::array<int, 5> another_array{5, 6, 7, 8, 9}; |
39 | | - ConcatView another_view = make_concat_view(another_array.data(), another_array.data() + another_array.size()); |
| 37 | + std::array<int, 5> array1{0, 1, 2, 3, 4}; |
| 38 | + std::array<int, 5> array2{5, 6, 7, 8, 9}; |
| 39 | + |
| 40 | + View v1{Iterator(array1.data()), Sentinel(Iterator(array1.data() + array1.size()))}; |
| 41 | + View v2{Iterator(array2.data()), Sentinel(Iterator(array2.data() + array2.size()))}; |
| 42 | + std::ranges::concat_view view(std::move(v1), std::move(v2)); |
| 43 | + |
40 | 44 | auto it1 = view.begin(); |
41 | | - auto it2 = another_view.begin(); |
| 45 | + auto it2 = ++view.begin(); |
42 | 46 |
|
43 | 47 | static_assert(std::is_same_v<decltype(iter_swap(it1, it2)), void>); |
44 | 48 | static_assert(noexcept(iter_swap(it1, it2)) == IsNoexcept); |
45 | 49 |
|
46 | | - assert(*it1 == 0 && *it2 == 5); // test the test |
| 50 | + assert(*it1 == 0 && *it2 == 1); |
47 | 51 | iter_swap(it1, it2); |
48 | | - assert(*it1 == 5); |
| 52 | + assert(*it1 == 1); |
49 | 53 | assert(*it2 == 0); |
50 | 54 | } |
| 55 | + |
| 56 | + { |
| 57 | + // iter swap may throw |
| 58 | + std::array<ThrowingMove, 2> iterSwapMayThrow{}; |
| 59 | + std::ranges::concat_view v(iterSwapMayThrow); |
| 60 | + auto iter1 = v.begin(); |
| 61 | + auto iter2 = ++v.begin(); |
| 62 | + static_assert(!noexcept(std::ranges::iter_swap(iter1, iter2))); |
| 63 | + } |
51 | 64 | } |
52 | 65 |
|
53 | 66 | constexpr bool tests() { |
|
0 commit comments