SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
range.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <seqan3/std/ranges>
16 
22 
23 namespace seqan3::detail
24 {
38 template <typename rng_t>
39 SEQAN3_CONCEPT debug_stream_range_guard =
40  !std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<rng_t>>,
41  std::remove_cvref_t<rng_t>> && // prevent recursive instantiation
42  // exclude null-terminated strings:
43  !(std::is_pointer_v<std::decay_t<rng_t>> &&
44  std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<rng_t>>, char>);
45 
57 template <std::ranges::range rng_t, typename char_t>
58 constexpr bool reference_type_is_streamable_v = false;
59 
61 template <std::ranges::range rng_t, typename char_t>
62  requires requires (std::ranges::range_reference_t<rng_t> l, debug_stream_type<char_t> s) { { s << l }; }
63 constexpr bool reference_type_is_streamable_v<rng_t, char_t> = true;
65 }
66 
67 namespace seqan3
68 {
91 template <typename char_t, std::ranges::input_range rng_t>
92 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, rng_t && r)
94  requires detail::debug_stream_range_guard<rng_t>
96 {
97  static_assert(detail::reference_type_is_streamable_v<rng_t, char_t>,
98  "The reference type of the passed range cannot be streamed into the debug_stream.");
99 
100  s << '[';
101  auto b = std::ranges::begin(r);
102  auto e = std::ranges::end(r);
103  if (b != e)
104  {
105  s << *b;
106  ++b;
107  }
108  while (b != e)
109  {
110  s << ',';
111  s << *b;
112  ++b;
113  }
114  s << ']';
115 
116  return s;
117 }
118 
135 template <typename char_t, sequence sequence_t>
136 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, sequence_t && sequence)
138  requires detail::debug_stream_range_guard<sequence_t> &&
139  (!detail::is_uint_adaptation_v<std::remove_cvref_t<std::ranges::range_reference_t<sequence_t>>>)
141 {
142  for (auto && chr : sequence)
143  s << chr;
144  return s;
145 }
146 
148 
149 } // namespace seqan3
Provides alphabet adaptations for standard char types.
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:76
Provides various transformation traits used by the range module.
Provides seqan3::debug_stream and related types.
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: debug_stream_alignment.hpp:101
The generic concept for a (biological) sequence.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Adaptations of concepts from the Ranges TS.
Additional non-standard concepts for ranges.
Provides alphabet adaptations for standard uint types.