SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
debug_stream_range.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 #include <seqan3/range/concept.hpp>
23 
24 namespace seqan3::detail
25 {
39 template <typename rng_t>
40 SEQAN3_CONCEPT debug_stream_range_guard =
41  !std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<rng_t>>,
42  std::remove_cvref_t<rng_t>> && // prevent recursive instantiation
43  // exclude null-terminated strings:
44  !(std::is_pointer_v<std::decay_t<rng_t>> &&
45  std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<rng_t>>, char>);
46 
58 template <std::ranges::range rng_t, typename char_t>
59 constexpr bool reference_type_is_streamable_v = false;
60 
62 template <std::ranges::range rng_t, typename char_t>
63  requires requires (std::ranges::range_reference_t<rng_t> l, debug_stream_type<char_t> s) { { s << l }; }
64 constexpr bool reference_type_is_streamable_v<rng_t, char_t> = true;
66 }
67 
68 namespace seqan3
69 {
92 template <typename char_t, std::ranges::input_range rng_t>
93 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, rng_t && r)
95  requires detail::debug_stream_range_guard<rng_t>
97 {
98  static_assert(detail::reference_type_is_streamable_v<rng_t, char_t>,
99  "The reference type of the passed range cannot be streamed into the debug_stream.");
100 
101  s << '[';
102  auto b = std::ranges::begin(r);
103  auto e = std::ranges::end(r);
104  if (b != e)
105  {
106  s << *b;
107  ++b;
108  }
109  while (b != e)
110  {
111  s << ',';
112  s << *b;
113  ++b;
114  }
115  s << ']';
116 
117  return s;
118 }
119 
121 template <typename char_t, sequence rng_t>
122 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, rng_t && r)
124  requires detail::debug_stream_range_guard<rng_t> &&
125  (!detail::is_uint_adaptation_v<std::remove_cvref_t<std::ranges::range_reference_t<rng_t>>>)
127 {
128  for (auto && l : r)
129  s << l;
130 
131  return s;
132 }
134 
135 } // namespace seqan3
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
concept.hpp
Additional non-standard concepts for ranges.
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:71
range.hpp
Provides various transformation traits used by the range module.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
char.hpp
Provides alphabet adaptations for standard char types.
ranges
Adaptations of concepts from the Ranges TS.
uint.hpp
Provides alphabet adaptations for standard uint types.
std::ranges::begin
T begin(T... args)
seqan3::operator<<
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:103
std::remove_cvref_t
concept.hpp
Core alphabet concept and free function/type trait wrappers.