Skip to content

Commit

Permalink
Merge pull request #1898 from smehringer/range_sequence_concept
Browse files Browse the repository at this point in the history
[FEATURE] add the seqan3::sequence concept
  • Loading branch information
smehringer committed Jun 22, 2020
2 parents 82707da + 11e8cf0 commit 487ca5e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include <iomanip>
#include <seqan3/std/ranges>
#include <tuple>

#include <range/v3/algorithm/for_each.hpp>
Expand All @@ -22,11 +23,11 @@
#include <seqan3/alphabet/gap/gapped.hpp>
#include <seqan3/core/concept/tuple.hpp>
#include <seqan3/core/detail/debug_stream_type.hpp>
#include <seqan3/range/concept.hpp>
#include <seqan3/range/container/concept.hpp>
#include <seqan3/range/views/slice.hpp>
#include <seqan3/range/views/to_char.hpp>
#include <seqan3/range/views/zip.hpp>
#include <seqan3/std/ranges>

// ---------------------------------------------------------------------------------------------------------------------
// unaligned_seq transformation trait
Expand Down Expand Up @@ -202,8 +203,8 @@ namespace seqan3
//!\cond
template <typename t>
SEQAN3_CONCEPT aligned_sequence =
sequence<t> &&
std::ranges::forward_range<t> &&
alphabet<std::ranges::range_reference_t<t>> &&
weakly_assignable_from<std::ranges::range_reference_t<t>, gap const &> &&
requires { typename detail::unaligned_seq_t<t>; } &&
requires (t v, detail::unaligned_seq_t<t> unaligned)
Expand Down
1 change: 1 addition & 0 deletions include/seqan3/alphabet/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
*
* We provide specialised containers with certain properties in the \ref range module.
*
* A container over an seqan3::alphabet automatically models the seqan3::sequence concept.
*/

#pragma once
Expand Down
48 changes: 27 additions & 21 deletions include/seqan3/core/detail/debug_stream_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

#pragma once

#include <seqan3/std/ranges>

#include <seqan3/alphabet/adaptation/char.hpp>
#include <seqan3/alphabet/adaptation/uint.hpp>
#include <seqan3/alphabet/concept.hpp>
#include <seqan3/core/detail/debug_stream_type.hpp>
#include <seqan3/core/type_traits/range.hpp>
#include <seqan3/std/ranges>
#include <seqan3/range/concept.hpp>

namespace seqan3::detail
{
Expand Down Expand Up @@ -96,34 +98,38 @@ inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, rng
static_assert(detail::reference_type_is_streamable_v<rng_t, char_t>,
"The reference type of the passed range cannot be streamed into the debug_stream.");

if constexpr (alphabet<std::ranges::range_reference_t<rng_t>> &&
!detail::is_uint_adaptation_v<remove_cvref_t<std::ranges::range_reference_t<rng_t>>>)
s << '[';
auto b = std::ranges::begin(r);
auto e = std::ranges::end(r);
if (b != e)
{
for (auto && l : r)
s << l;
s << *b;
++b;
}
else
while (b != e)
{
s << '[';
auto b = std::ranges::begin(r);
auto e = std::ranges::end(r);
if (b != e)
{
s << *b;
++b;
}
while (b != e)
{
s << ',';
s << *b;
++b;
}
s << ']';
s << ',';
s << *b;
++b;
}
s << ']';

return s;
}

//!\overload
template <sequence rng_t, typename char_t>
inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, rng_t && r)
//!\cond
requires detail::debug_stream_range_guard<rng_t> &&
!detail::is_uint_adaptation_v<remove_cvref_t<std::ranges::range_reference_t<rng_t>>>
//!\endcond
{
for (auto && l : r)
s << l;

return s;
}
//!\}

} // namespace seqan3
21 changes: 20 additions & 1 deletion include/seqan3/range/concept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <seqan3/std/ranges>

#include <seqan3/core/platform.hpp>
#include <seqan3/alphabet/concept.hpp>

namespace seqan3
{
Expand Down Expand Up @@ -135,4 +135,23 @@ SEQAN3_CONCEPT pseudo_random_access_range =
pseudo_random_access_iterator<std::ranges::iterator_t<rng_t>>;
//!\endcond

/*!\interface seqan3::sequence <>
* \brief The generic concept for a sequence.
* \ingroup range
* \extends std::ranges::input_range
*
* We define a range over an seqan3::alphabet as a *sequence*.
* A type models seqan3::sequence if it is at least an std::ranges::input_range
* and its references type models seqan3::alphabet.
*
* ### Concepts and doxygen
*
* The requirements for this concept are given as related functions and type traits.
* Types that model this concept are shown as "implementing this interface".
*/
//!\cond
template <typename rng_t>
SEQAN3_CONCEPT sequence = std::ranges::input_range<rng_t> && alphabet<std::ranges::range_reference_t<rng_t>>;
//!\endcond

} // namespace seqan3

0 comments on commit 487ca5e

Please sign in to comment.