SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
range.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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 <ranges>
16
22
23namespace seqan3::detail
24{
38template <typename rng_t>
39concept debug_stream_range_guard = !
40std::same_as<std::remove_cvref_t<std::ranges::range_reference_t<rng_t>>,
42 && // 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
58template <std::ranges::range rng_t, typename char_t>
59constexpr bool reference_type_is_streamable_v = false;
60
62template <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) {
64 {
65 s << l
66 };
67 }
68constexpr bool reference_type_is_streamable_v<rng_t, char_t> = true;
70} // namespace seqan3::detail
71
72namespace seqan3
73{
96template <typename char_t, std::ranges::input_range rng_t>
97inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, rng_t && r)
98 requires detail::debug_stream_range_guard<rng_t>
99{
100 static_assert(detail::reference_type_is_streamable_v<rng_t, char_t>,
101 "The reference type of the passed range cannot be streamed into the debug_stream.");
102
103 s << '[';
104 auto b = std::ranges::begin(r);
105 auto e = std::ranges::end(r);
106 if (b != e)
107 {
108 s << *b;
109 ++b;
110 }
111 while (b != e)
112 {
113 s << ',';
114 s << *b;
115 ++b;
116 }
117 s << ']';
118
119 return s;
120}
121
138template <typename char_t, sequence sequence_t>
139inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, sequence_t && sequence)
140 requires detail::debug_stream_range_guard<sequence_t>
141 && (!detail::is_uint_adaptation_v<std::remove_cvref_t<std::ranges::range_reference_t<sequence_t>>>)
142{
143 for (auto && chr : sequence)
144 s << chr;
145 return s;
146}
147
149
150} // namespace seqan3
T begin(T... args)
Provides alphabet adaptations for standard char types.
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:78
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:110
The generic concept for a (biological) sequence.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Additional non-standard concepts for ranges.
Provides alphabet adaptations for standard uint types.