| 1 |
#include <iterator> |
| 2 |
|
| 3 |
struct OutputIterator |
| 4 |
{ |
| 5 |
using iterator_category = std::output_iterator_tag; |
| 6 |
using difference_type = std::ptrdiff_t; |
| 7 |
using value_type = int; |
| 8 |
using pointer = value_type *; |
| 9 |
using reference = value_type &; |
| 10 |
|
| 11 |
private: |
| 12 |
int d_value; |
| 13 |
|
| 14 |
public: |
| 15 |
OutputIterator(int init); |
| 16 |
|
| 17 |
// standard: |
| 18 |
bool operator==(OutputIterator const &other) const; |
| 19 |
bool operator!=(OutputIterator const &other) const; |
| 20 |
int &operator*(); |
| 21 |
OutputIterator &operator++(); |
| 22 |
|
| 23 |
// consider: |
| 24 |
int *operator->(); |
| 25 |
}; |
| 26 |
|
| 27 |
OutputIterator::OutputIterator(int init) |
| 28 |
: |
| 29 |
d_value(init) |
| 30 |
{} |
| 31 |
|
| 32 |
bool OutputIterator::operator!=(OutputIterator const &other) const |
| 33 |
{ |
| 34 |
return d_value != other.d_value; |
| 35 |
} |
| 36 |
|
| 37 |
bool OutputIterator::operator==(OutputIterator const &other) const |
| 38 |
{ |
| 39 |
return d_value == other.d_value; |
| 40 |
} |
| 41 |
|
| 42 |
OutputIterator &OutputIterator::operator++() |
| 43 |
{ |
| 44 |
return *this; |
| 45 |
} |
| 46 |
|
| 47 |
int &OutputIterator::operator*() |
| 48 |
{ |
| 49 |
return d_value; |
| 50 |
} |