SeqAn3  3.0.1
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 
19 #include <seqan3/std/ranges>
20 
21 namespace seqan3::detail
22 {
36 template <typename rng_t>
37 SEQAN3_CONCEPT debug_stream_range_guard =
38  !std::same_as<remove_cvref_t<reference_t<rng_t>>, remove_cvref_t<rng_t>> && // prevent recursive instantiation
39  // exclude null-terminated strings:
40  !(std::is_pointer_v<std::decay_t<rng_t>> && std::same_as<remove_cvref_t<reference_t<rng_t>>, char>);
41 
53 template <std::ranges::range rng_t, typename char_t>
54 constexpr bool reference_type_is_streamable_v = false;
55 
57 template <std::ranges::range rng_t, typename char_t>
58  requires requires (reference_t<rng_t> l, debug_stream_type<char_t> s) { { s << l }; }
59 constexpr bool reference_type_is_streamable_v<rng_t, char_t> = true;
61 }
62 
63 namespace seqan3
64 {
87 template <std::ranges::input_range rng_t, typename char_t>
90  requires detail::debug_stream_range_guard<rng_t>
92 {
93  static_assert(detail::reference_type_is_streamable_v<rng_t, char_t>,
94  "The reference type of the passed range cannot be streamed into the debug_stream.");
95 
96  if constexpr (alphabet<reference_t<rng_t>> &&
97  !detail::is_uint_adaptation_v<remove_cvref_t<reference_t<rng_t>>>)
98  {
99  for (auto && l : r)
100  s << l;
101  }
102  else
103  {
104  s << '[';
105  auto b = begin(r);
106  auto e = end(r);
107  if (b != e)
108  {
109  s << *b;
110  ++b;
111  }
112  while (b != e)
113  {
114  s << ',';
115  s << *b;
116  ++b;
117  }
118  s << ']';
119  }
120 
121  return s;
122 }
123 
125 
126 } // namespace seqan3
seqan3::reference_t
typename reference< t >::type reference_t
Shortcut for seqan3::reference (transformation_trait shortcut).
Definition: pre.hpp:77
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:36
ranges
Adaptations of concepts from the Ranges TS.
seqan3::operator<<
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, tuple_t const &alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: aligned_sequence_concept.hpp:559
alphabet
The generic alphabet concept that covers most data types used in ranges.
std::remove_cv_t
all.hpp
Meta-header for the adaptation submodule; includes all headers from alphabet/adaptation/.
concept.hpp
Core alphabet concept and free function/type trait wrappers.