SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
out_file_iterator.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 <cassert>
16 
17 #include <range/v3/range_fwd.hpp>
18 
19 #include <seqan3/core/platform.hpp>
20 
21 #include <seqan3/std/ranges>
22 
23 namespace seqan3::detail
24 {
25 
48 template <typename file_type>
49 class out_file_iterator
50 {
51  static_assert(!std::is_const_v<file_type>,
52  "You cannot iterate over const files, because the iterator changes the file.");
53 public:
59  using value_type = void;
62  using reference = void;
64  using const_reference = void;
66  using size_type = void;
68  using difference_type = std::ptrdiff_t;
70  using pointer = void *;
72  using iterator_category = std::output_iterator_tag;
74 
78  constexpr out_file_iterator() = default;
81  constexpr out_file_iterator(out_file_iterator const &) = default;
83  constexpr out_file_iterator & operator=(out_file_iterator const &) = default;
85  constexpr out_file_iterator (out_file_iterator &&) = default;
87  constexpr out_file_iterator & operator=(out_file_iterator &&) = default;
89  ~out_file_iterator() = default;
90 
92  constexpr out_file_iterator(file_type & _host) noexcept :
93  host{&_host}
94  {}
96 
100  out_file_iterator & operator++()
102  {
103  return *this;
104  }
105 
107  out_file_iterator operator++(int)
108  {
109  return *this;
110  }
111 
113 
114  out_file_iterator & operator*() noexcept
115  {
116  return *this;
117  }
118 
123  template <typename arg_t>
124  out_file_iterator & operator=(arg_t && arg)
125  {
126  assert(host != nullptr);
127  host->push_back(std::forward<arg_t>(arg));
128  return *this;
129  }
131 
137  constexpr bool operator==(std::ranges::default_sentinel_t const &) const noexcept
139  {
140  return false;
141  }
142 
144  constexpr bool operator!=(std::ranges::default_sentinel_t const &) const noexcept
145  {
146  return true;
147  }
148 
150  constexpr friend bool operator==(std::ranges::default_sentinel_t const &,
151  out_file_iterator const & it) noexcept
152  {
153  return (it == std::ranges::default_sentinel);
154  }
155 
157  constexpr friend bool operator!=(std::ranges::default_sentinel_t const &,
158  out_file_iterator const & it) noexcept
159  {
160  return (it != std::ranges::default_sentinel);
161  }
163 
164 private:
166  file_type * host{};
167 };
168 
169 } // namespace seqan3::detail
std::rel_ops::operator!=
T operator!=(T... args)
std::output_iterator_tag
ranges
Adaptations of concepts from the Ranges TS.
platform.hpp
Provides platform and dependency checks.
cassert
std::ptrdiff_t