Skip to content

Commit

Permalink
fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed May 31, 2022
1 parent 36577bc commit 4b55cda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/seqan3/utility/views/chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class chunk_view : public std::ranges::view_interface<chunk_view<urng_t>>
};

//!\brief A deduction guide for the view class template.
template <std::ranges::input_range rng_t>
chunk_view(rng_t &&, uint16_t const & chunk_size) -> chunk_view<seqan3::detail::all_t<rng_t>>;
template <std::ranges::range rng_t>
chunk_view(rng_t &&, uint16_t) -> chunk_view<seqan3::detail::all_t<rng_t>>;

// ---------------------------------------------------------------------------------------------------------------------
// chunk_view iterators (basic_input_iterator and basic_iterator)
Expand Down Expand Up @@ -449,7 +449,7 @@ class chunk_view<urng_t>::basic_iterator : public maybe_iterator_category<maybe_
~basic_iterator() = default; //!< Defaulted.

//!\brief Allow iterator on a const range to be constructible from an iterator over a non-const range.
constexpr explicit basic_iterator(basic_iterator<!const_range> const & it) noexcept
constexpr basic_iterator(basic_iterator<!const_range> const & it) noexcept
requires const_range
:
chunk_size{std::move(it.chunk_size)},
Expand Down
17 changes: 17 additions & 0 deletions test/unit/utility/views/chunk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,20 @@ TYPED_TEST(chunk_view_test, underlying_input_range_test)
EXPECT_EQ(*(*v_it).begin(), *expected_it);
}
}

TYPED_TEST(chunk_view_test, use_on_temporaries)
{
if constexpr (!std::is_const_v<TypeParam>)
{
TypeParam text{1, 4, 2, 7, 4, 5, 8, 3, 4, 7, 5, 4, 3};
std::vector<std::vector<int>> expected_range{{1, 4, 2, 7}, {4, 5, 8, 3}, {4, 7, 5, 4}, {3}};

size_t i{};
for (auto && chunk : seqan3::views::chunk(TypeParam{1, 4, 2, 7, 4, 5, 8, 3, 4, 7, 5, 4, 3}, 4))
{
EXPECT_RANGE_EQ(chunk, expected_range[i]);
++i;
}
EXPECT_EQ(i, 4u);
}
}

0 comments on commit 4b55cda

Please sign in to comment.