Skip to content

Commit

Permalink
fix iterator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huixie90 committed May 31, 2024
1 parent f8b91a2 commit 17e84b2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 52 deletions.
28 changes: 17 additions & 11 deletions impl/any_view/test/iterator/bidirectional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace {

using AnyView =
std::ranges::any_view<int&, std::ranges::category::bidirectional>;
using Iter = AnyView::any_iterator;
using Iter = std::ranges::iterator_t<AnyView>;

static_assert(std::bidirectional_iterator<Iter>);
static_assert(!std::random_access_iterator<Iter>);
Expand All @@ -29,9 +29,10 @@ static_assert(std::same_as<typename std::iterator_traits<Iter>::difference_type,
ptrdiff_t>);

constexpr void basic() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();
{
std::same_as<int&> decltype(auto) r = *iter;
assert(r == 1);
Expand All @@ -56,9 +57,10 @@ constexpr void basic() {
}

constexpr void move() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(std::move(iter1));

assert(*iter1 == 1);
Expand All @@ -75,9 +77,10 @@ constexpr void move() {
}

constexpr void copy() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(iter1);

assert(*iter1 == 1);
Expand All @@ -94,8 +97,10 @@ constexpr void copy() {
}

constexpr void equal() {
std::array v{1, 2, 3, 4, 5};
Iter iter1(v.begin());
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1 = v.begin();
Iter iter2(iter1);

std::same_as<bool> decltype(auto) r = iter1 == iter2;
Expand All @@ -106,9 +111,10 @@ constexpr void equal() {
}

constexpr void decrement() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();
++iter;
++iter;
++iter;
Expand Down
27 changes: 16 additions & 11 deletions impl/any_view/test/iterator/forward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace {

using AnyView = std::ranges::any_view<int&, std::ranges::category::forward>;
using Iter = AnyView::any_iterator;
using Iter = std::ranges::iterator_t<AnyView>;

static_assert(std::forward_iterator<Iter>);
static_assert(!std::bidirectional_iterator<Iter>);
Expand All @@ -28,9 +28,10 @@ static_assert(std::same_as<typename std::iterator_traits<Iter>::difference_type,
ptrdiff_t>);

constexpr void basic() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();
{
std::same_as<int&> decltype(auto) r = *iter;
assert(r == 1);
Expand All @@ -55,9 +56,10 @@ constexpr void basic() {
}

constexpr void default_ctor() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();

Iter iter1, iter2;

Expand All @@ -69,9 +71,10 @@ constexpr void default_ctor() {
}

constexpr void move() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(std::move(iter1));

assert(*iter1 == 1);
Expand All @@ -88,9 +91,10 @@ constexpr void move() {
}

constexpr void copy() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(iter1);

assert(*iter1 == 1);
Expand All @@ -107,8 +111,9 @@ constexpr void copy() {
}

constexpr void equal() {
std::array v{1, 2, 3, 4, 5};
Iter iter1(v.begin());
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));
Iter iter1 = v.begin();
Iter iter2(iter1);

std::same_as<bool> decltype(auto) r = iter1 == iter2;
Expand Down
12 changes: 7 additions & 5 deletions impl/any_view/test/iterator/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace {

using AnyView = std::ranges::any_view<int&, std::ranges::category::input>;
using Iter = AnyView::any_iterator;
using Iter = std::ranges::iterator_t<AnyView>;

static_assert(std::input_iterator<Iter>);
static_assert(!std::forward_iterator<Iter>);
Expand All @@ -24,9 +24,10 @@ concept has_iterator_category = requires() { typename T::iterator_category; };
static_assert(!has_iterator_category<Iter>);

constexpr void basic() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter =v.begin();
{
std::same_as<int&> decltype(auto) r = *iter;
assert(r == 1);
Expand All @@ -51,9 +52,10 @@ constexpr void basic() {
}

constexpr void move() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(std::move(iter1));

assert(*iter1 == 1);
Expand Down
25 changes: 15 additions & 10 deletions impl/any_view/test/iterator/input_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace {

using AnyView = std::ranges::any_view<int&, std::ranges::category::input |
std::ranges::category::common>;
using Iter = AnyView::any_iterator;
using Iter = std::ranges::iterator_t<AnyView>;

static_assert(std::input_iterator<Iter>);
static_assert(!std::forward_iterator<Iter>);
Expand All @@ -25,9 +25,10 @@ concept has_iterator_category = requires() { typename T::iterator_category; };
static_assert(!has_iterator_category<Iter>);

constexpr void basic() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();
{
std::same_as<int&> decltype(auto) r = *iter;
assert(r == 1);
Expand All @@ -52,9 +53,10 @@ constexpr void basic() {
}

constexpr void move() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(std::move(iter1));

assert(*iter1 == 1);
Expand All @@ -71,9 +73,10 @@ constexpr void move() {
}

constexpr void copy() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(iter1);

assert(*iter1 == 1);
Expand All @@ -90,9 +93,11 @@ constexpr void copy() {
}

constexpr void equal() {
std::array v{1, 2, 3, 4, 5};
Iter iter1(v.begin());
Iter iter2(v.begin());
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1 = v.begin();
Iter iter2 = v.begin();

std::same_as<bool> decltype(auto) r = iter1 == iter2;
assert(r);
Expand Down
38 changes: 23 additions & 15 deletions impl/any_view/test/iterator/random_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace {

using AnyView =
std::ranges::any_view<int&, std::ranges::category::random_access>;
using Iter = AnyView::any_iterator;
using Iter = std::ranges::iterator_t<AnyView>;

static_assert(std::random_access_iterator<Iter>);
static_assert(!std::contiguous_iterator<Iter>);
Expand All @@ -29,9 +29,10 @@ static_assert(std::same_as<typename std::iterator_traits<Iter>::difference_type,
ptrdiff_t>);

constexpr void basic() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();
{
std::same_as<int&> decltype(auto) r = *iter;
assert(r == 1);
Expand All @@ -56,9 +57,10 @@ constexpr void basic() {
}

constexpr void move() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(std::move(iter1));

assert(*iter1 == 1);
Expand All @@ -75,9 +77,10 @@ constexpr void move() {
}

constexpr void copy() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter2(iter1);

assert(*iter1 == 1);
Expand All @@ -94,8 +97,10 @@ constexpr void copy() {
}

constexpr void equal() {
std::array v{1, 2, 3, 4, 5};
Iter iter1(v.begin());
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1 = v.begin();
Iter iter2(iter1);

std::same_as<bool> decltype(auto) r = iter1 == iter2;
Expand All @@ -106,9 +111,10 @@ constexpr void equal() {
}

constexpr void decrement() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();
++iter;
++iter;
++iter;
Expand All @@ -129,9 +135,10 @@ constexpr void decrement() {
}

constexpr void random_access() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter(v.begin());
Iter iter = v.begin();

{
std::same_as<Iter&> decltype(auto) r = iter += 3;
Expand Down Expand Up @@ -183,9 +190,10 @@ constexpr void random_access() {
}

constexpr void compare() {
std::array v{1, 2, 3, 4, 5};
std::array a{1, 2, 3, 4, 5};
AnyView v(std::views::all(a));

Iter iter1(v.begin());
Iter iter1 = v.begin();
Iter iter1_copy = iter1;

Iter iter4(v.begin() + 3);
Expand Down

0 comments on commit 17e84b2

Please sign in to comment.