Skip to content

Commit 965f7c4

Browse files
fix tests
1 parent f14dc74 commit 965f7c4

File tree

10 files changed

+55
-61
lines changed

10 files changed

+55
-61
lines changed

libcxx/include/__ranges/concat_view.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,15 @@ class concat_view<_Views...>::__iterator : public __concat_view_iterator_categor
578578
!__x.__it_.valueless_by_exception(),
579579
"Trying to subtract a valuess iterators of concat_view from the default sentinel.");
580580
return __x.__invoke_at_index([&]<std::size_t __index_x>() -> difference_type {
581-
auto __dx = ranges::distance(ranges::begin(std::get<__index_x>(__x.__parent_->__views_)), __x.__it_);
581+
auto __dx =
582+
ranges::distance(std::get<__index_x>(__x.__it_), ranges::end(std::get<__index_x>(__x.__parent_->__views_)));
582583
difference_type __s = [&]<std::size_t __start, std::size_t __end>(this auto&& self) -> difference_type {
583584
if constexpr (__start < __end) {
584585
return ranges::size(std::get<__start>(__x.__parent_->__views_)) +
585586
self.template operator()<__start + 1, __end>();
586587
}
587588
return 0;
588-
}.template operator()<0, __index_x>();
589+
}.template operator()<__index_x + 1, sizeof...(_Views)>();
589590
return -(__dx + __s);
590591
});
591592
}
@@ -595,7 +596,7 @@ class concat_view<_Views...>::__iterator : public __concat_view_iterator_categor
595596
...) &&
596597
(__apply_drop_first<_Const, _Views...>::value)
597598
{
598-
-(__x - default_sentinel);
599+
return -(__x - default_sentinel);
599600
}
600601
};
601602

libcxx/test/std/ranges/range.adaptors/range.concat/adaptor.pass.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99
// REQUIRES: std-at-least-c++26
1010

1111
#include <ranges>
12-
1312
#include <cassert>
14-
#include <concepts>
1513
#include <initializer_list>
16-
#include <type_traits>
17-
#include <utility>
18-
#include <vector>
1914

2015
#include "test_iterators.h"
2116
#include "test_range.h"

libcxx/test/std/ranges/range.adaptors/range.concat/begin.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ constexpr void general_tests() {
2020
// Check the return type of `.begin()`
2121
{
2222
std::ranges::concat_view view(v1, v2);
23-
using FilterIterator = std::ranges::iterator_t<decltype(view)>;
24-
ASSERT_SAME_TYPE(FilterIterator, decltype(view.begin()));
23+
using ConcatIterator = std::ranges::iterator_t<decltype(view)>;
24+
ASSERT_SAME_TYPE(ConcatIterator, decltype(view.begin()));
2525
}
2626
}
2727

libcxx/test/std/ranges/range.adaptors/range.concat/ctor.view.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
#include <cassert>
1212
#include <ranges>
13-
#include <utility>
1413

15-
#include "test_convertible.h"
1614
#include "test_macros.h"
1715
#include "types.h"
1816

libcxx/test/std/ranges/range.adaptors/range.concat/end.pass.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include <ranges>
1212

1313
#include <cassert>
14-
#include <concepts>
15-
#include <type_traits>
16-
#include <iterator>
1714
#include "test_iterators.h"
1815

1916
struct Range : std::ranges::view_base {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212

1313
#include <array>
1414
#include <cassert>
15-
#include <concepts>
16-
#include <utility>
17-
#include <__type_traits/maybe_const.h>
1815
#include "test_iterators.h"
19-
#include "test_macros.h"
2016
#include "test_range.h"
2117

2218
#include "../types.h"

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@
1212

1313
#include <array>
1414
#include <cassert>
15-
#include <concepts>
16-
#include <iterator>
17-
#include <utility>
18-
#include <vector>
19-
#include "test_iterators.h"
2015
#include "test_macros.h"
2116
#include "../types.h"
22-
#include <iostream>
2317

2418
constexpr void test() {
2519
// Test with a single satisfied value
@@ -82,36 +76,6 @@ constexpr void test() {
8276
assert(result == view.end());
8377
assert(it == (result - 1));
8478
}
85-
86-
// Test two iterators
87-
{
88-
std::array<int, 5> array1{0, 1};
89-
std::array<int, 5> array2{2, 3};
90-
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
91-
auto it1 = view.begin();
92-
it1++;
93-
it1++;
94-
auto it2 = view.begin();
95-
auto res = it1 - it2;
96-
std::cout << res << std::endl;
97-
assert(res == 2);
98-
}
99-
100-
// Test one iterator and one sentinel
101-
{
102-
std::array<int, 5> array1{0, 1};
103-
std::array<int, 5> array2{2, 3};
104-
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
105-
auto it1 = view.begin();
106-
it1++;
107-
it1++;
108-
it1++;
109-
it1++;
110-
auto it2 = view.begin();
111-
auto res = it1 - it2;
112-
std::cout << res << std::endl;
113-
assert(res == 4);
114-
}
11579
}
11680

11781
int main(int, char**) {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212

1313
#include <array>
1414
#include <cassert>
15-
#include <concepts>
16-
#include <cstddef>
17-
#include <utility>
1815
#include "test_iterators.h"
19-
#include "test_macros.h"
2016
#include "../types.h"
2117

2218
template <class Iter, class ValueType = int, class Sent = sentinel_wrapper<Iter>>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
#include <ranges>
1212

13-
#include <iostream>
1413
#include <array>
1514
#include <cassert>
1615
#include <concepts>
1716
#include <type_traits>
1817
#include <utility>
1918
#include "test_iterators.h"
20-
#include "test_macros.h"
2119
#include "../types.h"
2220

2321
template <class Iterator>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++26
10+
11+
#include <ranges>
12+
13+
#include <array>
14+
#include <cassert>
15+
#include <iterator>
16+
#include "test_iterators.h"
17+
#include "test_macros.h"
18+
#include "../types.h"
19+
20+
constexpr void test() {
21+
22+
// Test two iterators
23+
{
24+
std::array<int, 2> array1{0, 1};
25+
std::array<int, 2> array2{2, 3};
26+
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
27+
auto it1 = view.begin();
28+
it1++;
29+
it1++;
30+
auto it2 = view.begin();
31+
auto res = it1 - it2;
32+
assert(res == 2);
33+
}
34+
35+
// Test one iterator and one sentinel
36+
{
37+
std::array<int, 2> array1{0, 1};
38+
std::array<int, 2> array2{2, 3};
39+
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
40+
auto it1 = view.begin();
41+
auto res = std::default_sentinel_t{} - it1;
42+
assert(res == 4);
43+
}
44+
}
45+
46+
int main(int, char**) {
47+
test();
48+
return 0;
49+
}

0 commit comments

Comments
 (0)