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 
20 #include <seqan3/std/ranges>
21 
22 namespace seqan3::detail
23 {
37 template <typename rng_t>
38 SEQAN3_CONCEPT debug_stream_range_guard =
40  remove_cvref_t<rng_t>> && // prevent recursive instantiation
41  // exclude null-terminated strings:
42  !(std::is_pointer_v<std::decay_t<rng_t>> &&
44 
56 template <std::ranges::range rng_t, typename char_t>
57 constexpr bool reference_type_is_streamable_v = false;
58 
60 template <std::ranges::range rng_t, typename char_t>
61  requires requires (std::ranges::range_reference_t<rng_t> l, debug_stream_type<char_t> s) { { s << l }; }
62 constexpr bool reference_type_is_streamable_v<rng_t, char_t> = true;
64 }
65 
66 namespace seqan3
67 {
90 template <std::ranges::input_range rng_t, typename char_t>
93  requires detail::debug_stream_range_guard<rng_t>
95 {
96  static_assert(detail::reference_type_is_streamable_v<rng_t, char_t>,
97  "The reference type of the passed range cannot be streamed into the debug_stream.");
98 
99  if constexpr (alphabet<std::ranges::range_reference_t<rng_t>> &&
100  !detail::is_uint_adaptation_v<remove_cvref_t<std::ranges::range_reference_t<rng_t>>>)
101  {
102  for (auto && l : r)
103  s << l;
104  }
105  else
106  {
107  s << '[';
108  auto b = std::ranges::begin(r);
109  auto e = std::ranges::end(r);
110  if (b != e)
111  {
112  s << *b;
113  ++b;
114  }
115  while (b != e)
116  {
117  s << ',';
118  s << *b;
119  ++b;
120  }
121  s << ']';
122  }
123 
124  return s;
125 }
126 
128 
129 } // namespace seqan3
seqan3::detail::is_uint_adaptation_v
constexpr bool is_uint_adaptation_v
Whether a type is uint8_t, uint16_t or uint32_t.
Definition: uint.hpp:37
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:70
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
range.hpp
Provides various transformation traits used by the range module.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:35
seqan3::operator<<
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, tuple_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: aligned_sequence_concept.hpp:562
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.
seqan3::detail::reference_type_is_streamable_v
constexpr bool reference_type_is_streamable_v
Helper template variable that checks if the reference type of a range can be streamed into an instanc...
Definition: debug_stream_range.hpp:57
alphabet
The generic alphabet concept that covers most data types used in ranges.
seqan3::detail::debug_stream_range_guard
SEQAN3_CONCEPT debug_stream_range_guard
A helper concept definition for ranges that can be streamed to the seqan3::debug_stream.
Definition: debug_stream_range.hpp:38
std::remove_cv_t
seqan3::detail
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:35
concept.hpp
Core alphabet concept and free function/type trait wrappers.