SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
out_file_iterator.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 <cassert>
16#include <ranges>
17
19
20namespace seqan3::detail
21{
22
45template <typename file_type>
46class out_file_iterator
47{
48 static_assert(!std::is_const_v<file_type>,
49 "You cannot iterate over const files, because the iterator changes the file.");
50
51public:
58 using value_type = void;
60 using reference = void;
62 using const_reference = void;
64 using size_type = void;
66 using difference_type = std::ptrdiff_t;
68 using pointer = void *;
70 using iterator_category = std::output_iterator_tag;
72
77 constexpr out_file_iterator() = default;
79 constexpr out_file_iterator(out_file_iterator const &) = default;
81 constexpr out_file_iterator & operator=(out_file_iterator const &) = default;
83 constexpr out_file_iterator(out_file_iterator &&) = default;
85 constexpr out_file_iterator & operator=(out_file_iterator &&) = default;
87 ~out_file_iterator() = default;
88
90 constexpr out_file_iterator(file_type & _host) noexcept : host{&_host}
91 {}
93
98 out_file_iterator & operator++()
99 {
100 return *this;
101 }
102
104 out_file_iterator operator++(int)
105 {
106 return *this;
107 }
108
110
111 out_file_iterator & operator*() noexcept
112 {
113 return *this;
114 }
115
120 template <typename arg_t>
121 out_file_iterator & operator=(arg_t && arg)
122 {
123 assert(host != nullptr);
124 host->push_back(std::forward<arg_t>(arg));
125 return *this;
126 }
128
135 constexpr bool operator==(std::default_sentinel_t const &) const noexcept
136 {
137 return false;
138 }
139
141 constexpr bool operator!=(std::default_sentinel_t const &) const noexcept
142 {
143 return true;
144 }
145
147 constexpr friend bool operator==(std::default_sentinel_t const &, out_file_iterator const & it) noexcept
148 {
149 return (it == std::default_sentinel);
150 }
151
153 constexpr friend bool operator!=(std::default_sentinel_t const &, out_file_iterator const & it) noexcept
154 {
155 return (it != std::default_sentinel);
156 }
158
159private:
161 file_type * host{};
162};
163
164} // namespace seqan3::detail
T operator!=(T... args)
Provides platform and dependency checks.