SeqAn3  3.0.2
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 #include <seqan3/std/ranges>
17 
18 #include <seqan3/core/platform.hpp>
19 
20 namespace seqan3::detail
21 {
22 
45 template <typename file_type>
46 class 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 public:
56  using value_type = void;
59  using reference = void;
61  using const_reference = void;
63  using size_type = void;
65  using difference_type = std::ptrdiff_t;
67  using pointer = void *;
69  using iterator_category = std::output_iterator_tag;
71 
75  constexpr out_file_iterator() = default;
78  constexpr out_file_iterator(out_file_iterator const &) = default;
80  constexpr out_file_iterator & operator=(out_file_iterator const &) = default;
82  constexpr out_file_iterator (out_file_iterator &&) = default;
84  constexpr out_file_iterator & operator=(out_file_iterator &&) = default;
86  ~out_file_iterator() = default;
87 
89  constexpr out_file_iterator(file_type & _host) noexcept :
90  host{&_host}
91  {}
93 
97  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 
134  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 &,
148  out_file_iterator const & it) noexcept
149  {
150  return (it == std::default_sentinel);
151  }
152 
154  constexpr friend bool operator!=(std::default_sentinel_t const &,
155  out_file_iterator const & it) noexcept
156  {
157  return (it != std::default_sentinel);
158  }
160 
161 private:
163  file_type * host{};
164 };
165 
166 } // 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