Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] introduce ranges::to; remove implicit conversions #1033

Merged
merged 1 commit into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions include/seqan3/range/view/persist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,6 @@ class view_persist : public ranges::view_interface<view_persist<urng_t>>
return end();
}
//!\}

/*!\brief Convert this view into a container implicitly.
* \tparam container_t Type of the container to convert to; must satisfy seqan3::SequenceContainer and the
* seqan3::reference_t of both must model std::CommonReference.
* \returns This view converted to container_t.
*/
template <SequenceContainer container_t>
operator container_t() const
//!\cond
requires std::CommonReference<reference_t<std::remove_reference_t<container_t>>, reference>
//!\endcond
{
container_t ret;
std::ranges::copy(begin(), end(), std::back_inserter(ret));
return ret;
}
};

//!\brief Template argument type deduction guide that strips references.
Expand Down
28 changes: 0 additions & 28 deletions include/seqan3/range/view/take.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,34 +430,6 @@ class view_take : public ranges::view_interface<view_take<urng_t, exactly, or_th
{
return target_size;
}

/*!\brief Convert this view into a container implicitly.
* \tparam container_t Type of the container to convert to; must satisfy seqan3::SequenceContainer and the
* seqan3::reference_t of both must model std::CommonReference.
* \returns This view converted to container_t.
*/
template <SequenceContainer container_t>
operator container_t()
//!\cond
requires std::CommonReference<reference_t<container_t>, reference>
//!\endcond
{
container_t ret;
std::ranges::copy(begin(), end(), std::back_inserter(ret));
return ret;
}

//!\overload
template <SequenceContainer container_t>
operator container_t() const
//!\cond
requires ConstIterableRange<urng_t> && std::CommonReference<reference_t<container_t>, const_reference>
//!\endcond
{
container_t ret;
std::ranges::copy(cbegin(), cend(), std::back_inserter(ret));
return ret;
}
};

//!\brief Template argument type deduction guide that strips references.
Expand Down
28 changes: 0 additions & 28 deletions include/seqan3/range/view/take_until.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,34 +470,6 @@ class view_take_until : public ranges::view_interface<view_take_until<urng_t, fu
return std::ranges::cend(urange);
}
//!\}

/*!\brief Convert this view into a container implicitly.
* \tparam container_t Type of the container to convert to; must model seqan3::SequenceContainer and it's
* seqan3::reference_t must model std::CommonReference with `reference`.
* \returns This view converted to container_t.
*/
template <SequenceContainer container_t>
operator container_t()
//!\cond
requires std::CommonReference<reference_t<container_t>, reference>
//!\endcond
{
container_t ret;
std::ranges::copy(begin(), end(), std::back_inserter(ret));
return ret;
}

//!\overload
template <SequenceContainer container_t>
operator container_t() const
//!\cond
requires ConstIterableRange<urng_t> && std::CommonReference<reference_t<container_t>, const_reference>
//!\endcond
{
container_t ret;
std::ranges::copy(cbegin(), cend(), std::back_inserter(ret));
return ret;
}
};

//!\brief Type deduction guide that strips references.
Expand Down
6 changes: 6 additions & 0 deletions include/seqan3/std/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ using SEQAN3_DOXYGEN_ONLY(cend =) ::ranges::cend;
*/
template <typename urng_t>
using view_interface = ::ranges::view_interface<urng_t>;

/*!\typedef std::ranges::to
* \brief Alias for ranges::to.
*/
using SEQAN3_DOXYGEN_ONLY(to =) ::ranges::_to_::to;
//!\}

} // namespace std::ranges

// -----------------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions test/unit/range/view/view_char_to_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ TEST(view_char_to, basic)
dna5_vector cmp{"ACTTTGATA"_dna5};

// pipe notation
dna5_vector v = vec | view::char_to<dna5>;
dna5_vector v = vec | view::char_to<dna5> | std::ranges::to<std::vector>;
EXPECT_EQ(cmp, v);

// function notation
dna5_vector v2(view::char_to<dna5>(vec));
dna5_vector v2(view::char_to<dna5>(vec) | std::ranges::to<std::vector>);
EXPECT_EQ(cmp, v2);

// combinability
dna5_vector cmp2{"ATAGTTTCA"_dna5};
dna5_vector v3 = vec | view::char_to<dna5> | std::view::reverse;
dna5_vector v3 = vec | view::char_to<dna5> | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(cmp2, v3);
}

TEST(view_char_to, deep_view)
{
std::vector<std::string> foo{"ACGTA", "TGCAT"};

std::vector<dna5_vector> v = foo | view::char_to<dna5>;
std::vector<dna5_vector> v = foo | view::char_to<dna5> | std::ranges::to<std::vector<dna5_vector>>;

ASSERT_EQ(size(v), 2u);
EXPECT_TRUE((std::ranges::equal(v[0], "ACGTA"_dna5)));
Expand Down
12 changes: 6 additions & 6 deletions test/unit/range/view/view_complement_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ TEST(view_complement, basic)
dna5_vector foo{"ACGTA"_dna5};

// pipe notation
dna5_vector v = foo | view::complement;
dna5_vector v = foo | view::complement | std::ranges::to<std::vector>;
EXPECT_EQ(v, "TGCAT"_dna5);

// function notation
dna5_vector v2(view::complement(foo));
dna5_vector v2(view::complement(foo) | std::ranges::to<std::vector>);
EXPECT_EQ(v2, "TGCAT"_dna5);

// combinability
dna5_vector v3 = foo | view::complement | std::view::reverse;
dna5_vector v3 = foo | view::complement | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(v3, "TACGT"_dna5);

dna5_vector const bar{"ACGTA"_dna5};

// const pipe notation
dna5_vector v4 = bar | view::complement;
dna5_vector v4 = bar | view::complement | std::ranges::to<std::vector>;
EXPECT_EQ(v4, "TGCAT"_dna5);

// const function notation
dna5_vector v5(view::complement(bar));
dna5_vector v5(view::complement(bar) | std::ranges::to<std::vector>);
EXPECT_EQ(v5, "TGCAT"_dna5);

// const combinability
dna5_vector v6 = bar | view::complement | std::view::reverse;
dna5_vector v6 = bar | view::complement | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(v6, "TACGT"_dna5);
}

Expand Down
12 changes: 6 additions & 6 deletions test/unit/range/view/view_convert_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ TEST(view_convert, basic)
std::vector<bool> cmp{1, 1, 0, 1, 0, 0, 1, 1, 1};

// pipe notation
std::vector<bool> v = vec | view::convert<bool>;
std::vector<bool> v = vec | view::convert<bool> | std::ranges::to<std::vector>;
EXPECT_EQ(cmp, v);

// function notation
std::vector<bool> v2(view::convert<bool>(vec));
std::vector<bool> v2(view::convert<bool>(vec) | std::ranges::to<std::vector>);
EXPECT_EQ(cmp, v2);

// combinability
std::vector<bool> cmp2{1, 1, 1, 0, 0, 1, 0, 1, 1};
std::vector<bool> v3 = vec | view::convert<bool> | std::view::reverse;
std::vector<bool> v3 = vec | view::convert<bool> | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(cmp2, v3);
}

Expand All @@ -41,16 +41,16 @@ TEST(view_convert, explicit_conversion)
dna4_vector cmp{"ACGATAGGA"_dna4};

// pipe notation
dna4_vector v = vec | view::convert<dna4>;
dna4_vector v = vec | view::convert<dna4> | std::ranges::to<std::vector>;
EXPECT_EQ(cmp, v);

// function notation
dna4_vector v2(view::convert<dna4>(vec));
dna4_vector v2(view::convert<dna4>(vec) | std::ranges::to<std::vector>);
EXPECT_EQ(cmp, v2);

// combinability
dna4_vector cmp2{"AGGATAGCA"_dna4};
dna4_vector v3 = vec | view::convert<dna4> | std::view::reverse;
dna4_vector v3 = vec | view::convert<dna4> | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(cmp2, v3);
}

Expand Down
24 changes: 12 additions & 12 deletions test/unit/range/view/view_deep_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ TEST(view_deep_reverse, basic)
dna5_vector foo{"ACGTA"_dna5};

// pipe notation, temporary
dna5_vector v0 = foo | view::deep{std::view::reverse};
dna5_vector v0 = foo | view::deep{std::view::reverse} | std::ranges::to<std::vector>;
EXPECT_EQ(v0, "ATGCA"_dna5);

// pipe notation
dna5_vector v = foo | view::deep_reverse;
dna5_vector v = foo | view::deep_reverse | std::ranges::to<std::vector>;
EXPECT_EQ(v, "ATGCA"_dna5);

// function notation
dna5_vector v2(view::deep_reverse(foo));
dna5_vector v2(view::deep_reverse(foo) | std::ranges::to<std::vector>);
EXPECT_EQ(v2, "ATGCA"_dna5);

// combinability
dna5_vector v3 = foo | view::deep_reverse | std::view::reverse;
dna5_vector v3 = foo | view::deep_reverse | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(v3, "ACGTA"_dna5);
}

Expand Down Expand Up @@ -106,19 +106,19 @@ TEST(view_deep_take, basic)
dna5_vector foo{"ACGTA"_dna5};

// pipe notation, temporary
dna5_vector v0 = foo | view::deep{ranges::view::take}(2);
dna5_vector v0 = foo | view::deep{ranges::view::take}(2) | std::ranges::to<std::vector>;
EXPECT_EQ(v0, "AC"_dna5);

// pipe notation
dna5_vector v = foo | view::deep_take(2);
dna5_vector v = foo | view::deep_take(2) | std::ranges::to<std::vector>;
EXPECT_EQ(v, "AC"_dna5);

// function notation
dna5_vector v2(view::deep_take(foo, 2));
dna5_vector v2(view::deep_take(foo, 2) | std::ranges::to<std::vector>);
EXPECT_EQ(v2, "AC"_dna5);

// combinability
dna5_vector v3 = foo | view::deep_take(2) | std::view::reverse;
dna5_vector v3 = foo | view::deep_take(2) | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(v3, "CA"_dna5);
}

Expand Down Expand Up @@ -151,19 +151,19 @@ TEST(view_deep_take2, basic)
dna5_vector foo{"ACGTA"_dna5};

// pipe notation, temporary
dna5_vector v0 = foo | view::deep{ranges::view::take(2)};
dna5_vector v0 = foo | view::deep{ranges::view::take(2)} | std::ranges::to<std::vector>;
EXPECT_EQ(v0, "AC"_dna5);

// pipe notation
dna5_vector v = foo | view::deep_take2;
dna5_vector v = foo | view::deep_take2 | std::ranges::to<std::vector>;
EXPECT_EQ(v, "AC"_dna5);

// function notation
dna5_vector v2(view::deep_take2(foo));
dna5_vector v2(view::deep_take2(foo) | std::ranges::to<std::vector>);
EXPECT_EQ(v2, "AC"_dna5);

// combinability
dna5_vector v3 = foo | view::deep_take2 | std::view::reverse;
dna5_vector v3 = foo | view::deep_take2 | std::view::reverse | std::ranges::to<std::vector>;
EXPECT_EQ(v3, "CA"_dna5);
}

Expand Down
11 changes: 6 additions & 5 deletions test/unit/range/view/view_drop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ void do_test(adaptor_t const & adaptor, std::string const & vec)
EXPECT_EQ("bar", std::string(v));

// function notation
std::string v2{adaptor(vec, 3)};
std::string v2{adaptor(vec, 3) | std::ranges::to<std::string>};
EXPECT_EQ("bar", v2);

// combinability
auto v3 = vec | adaptor(1) | adaptor(1) | ranges::view::unique;
EXPECT_EQ("obar", std::string(v3));
std::string v3b = vec | std::view::reverse | adaptor(3) | ranges::view::unique;
std::string v3b = vec | std::view::reverse | adaptor(3) | ranges::view::unique | std::ranges::to<std::string>;
EXPECT_EQ("of", v3b);

// store arg
auto a0 = adaptor(3);
auto v4 = vec | a0;
EXPECT_EQ("bar", std::string(v4));
EXPECT_EQ("bar", std::string(v4 | std::ranges::to<std::string>));

// store combined
auto a1 = adaptor(1) | adaptor(1) | ranges::view::unique;
auto v5 = vec | a1;
EXPECT_EQ("obar", std::string(v5));
EXPECT_EQ("obar", std::string(v5 | std::ranges::to<std::string>));
}

template <typename adaptor_t>
Expand Down Expand Up @@ -118,7 +118,8 @@ TEST(view_drop, underlying_is_shorter)
EXPECT_NO_THROW(( view::drop(vec, 4) )); // no parsing

std::string v;
EXPECT_NO_THROW(( v = vec | view::single_pass_input | view::drop(4) )); // full parsing on conversion
// full parsing on conversion
EXPECT_NO_THROW(( v = vec | view::single_pass_input | view::drop(4) | std::ranges::to<std::string>));
EXPECT_EQ("ar", v);
}

Expand Down
Loading