Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
null_output_iterator.hpp
1
2// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
3
4/*********************************************************************** * This program is free software; you can
5 *redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free
6 *Software Foundation; either version 2 of the License, or * (at your option) any later version. *
7 * *
8 ***************************************************************************/
9
10#ifndef __NULL_OUTPUT_ITERATOR_H_INCLUDED__
11#define __NULL_OUTPUT_ITERATOR_H_INCLUDED__
12
13#include <iterator>
14
15namespace quetzal::utils
16{
22template <typename T> class null_output_iterator
23{
24 private:
25 T _p;
26
27 public:
28 using iterator_category = std::forward_iterator_tag;
29 using value_type = T;
30 using difference_type = T;
31 using pointer = T *;
32 using reference = T &;
35 null_output_iterator(T p) : _p(p){};
39 void operator=(T p)
40 {
41 _p = p;
42 }
47 {
48 _p++;
49 return *this;
50 }
55 {
56 _p++;
57 return *this;
58 }
63 {
64 return *this;
65 }
69 {
70 return a._p == b._p;
71 };
72 friend bool operator!=(const null_output_iterator &a, const null_output_iterator &b)
73 {
74 return a._p != b._p;
75 };
76};
77} // namespace quetzal::utils
78
79#endif
Allows to discard the output of functions that requires an output iterator.
Definition null_output_iterator.hpp:23
null_output_iterator operator++(int)
Can be post-incremented.
Definition null_output_iterator.hpp:54
null_output_iterator(T p)
Constructor.
Definition null_output_iterator.hpp:35
friend bool operator==(const null_output_iterator &a, const null_output_iterator &b)
We want comparison it != end;.
Definition null_output_iterator.hpp:68
void operator=(T p)
Assignment.
Definition null_output_iterator.hpp:39
null_output_iterator & operator*()
Can be dereferenced.
Definition null_output_iterator.hpp:62
null_output_iterator & operator++()
Can be pre-incremented.
Definition null_output_iterator.hpp:46
Miscellaneous details.
Definition utils.hpp:21