Skip to content

Commit

Permalink
Merge pull request #103 from MarcDirven/dev
Browse files Browse the repository at this point in the history
Added next
  • Loading branch information
MarcDirven authored Jul 26, 2021
2 parents 56851ea + e0bc649 commit 371f9ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 0 additions & 11 deletions include/Lz/Lz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,6 @@ class IterView final : public internal::BasicIteratorView<Iterator> {
return lz::toIter(lz::flatten(*this));
}

/**
* Gets the nth element from this sequence.
* @param n The offset.
* @return The element referred to by `begin() + n`
*/
LZ_NODISCARD LZ_CONSTEXPR_CXX_20 reference next(const difference_type n = 1) const {
using lz::next;
using std::next;
return *next(Base::begin(), n);
}

//! See FunctionTools.hpp `isEmpty` for documentation.
LZ_NODISCARD LZ_CONSTEXPR_CXX_20 bool isEmpty() const {
return lz::isEmpty(*this);
Expand Down
13 changes: 13 additions & 0 deletions include/Lz/detail/BasicIteratorView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,19 @@ class BasicIteratorView {
using std::distance;
return distance(_begin, _end);
}

/**
* Gets the nth position of the iterator from this sequence.
* @param n The offset.
* @return The element referred to by `begin() + n`
*/
LZ_NODISCARD LZ_CONSTEXPR_CXX_20 LzIterator next(const internal::DiffType<LzIterator> n) const {
using lz::next;
using std::next;
return next(_begin, n);
}


}; // namespace internal
// clang-format on
} // namespace internal
Expand Down
2 changes: 1 addition & 1 deletion tests/lz-chain-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TEST_CASE("Iterator chaining") {
std::array<std::array<int, 3>, 3> toFlatten{};
CHECK(lz::equal(lz::toIter(toFlatten).flatten(), lz::repeat(0, 3 * 3)));

CHECK(lz::toIter(arr).next(1) == 1);
CHECK(*lz::toIter(arr).next(1) == 1);
CHECK(lz::toIter(arr).distance() == size);
CHECK(!lz::toIter(arr).isEmpty());
CHECK(!lz::toIter(arr).hasOne());
Expand Down

0 comments on commit 371f9ef

Please sign in to comment.