Itoyori  v0.0.1
count_iterator.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iterator>
4 
5 namespace ityr {
6 
32 template <typename T>
34  using this_t = count_iterator<T>;
35 
36 public:
37  using difference_type = std::ptrdiff_t;
38  using value_type = T;
39  using pointer = void;
40  using reference = T;
41  using iterator_category = std::random_access_iterator_tag;
42 
44  count_iterator(T val) : val_(val) {}
45 
46  reference operator*() const { return val_; }
47 
48  reference operator[](difference_type diff) const { return val_ + diff; }
49 
50  this_t& operator+=(difference_type diff) { val_ += diff; return *this; }
51  this_t& operator-=(difference_type diff) { val_ -= diff; return *this; }
52 
53  this_t& operator++() { ++val_; return *this; }
54  this_t& operator--() { --val_; return *this; }
55 
56  this_t operator++(int) { this_t tmp(*this); val_++; return tmp; }
57  this_t operator--(int) { this_t tmp(*this); val_--; return tmp; }
58 
59  this_t operator+(difference_type diff) const { return val_ + diff; }
60  this_t operator-(difference_type diff) const { return val_ - diff; }
61  difference_type operator-(const this_t& it) const { return val_ - *it; }
62 
63 private:
64  T val_;
65 };
66 
67 template <typename T>
68 inline bool operator==(const count_iterator<T>& it1, const count_iterator<T>& it2) {
69  return *it1 == *it2;
70 }
71 
72 template <typename T>
73 inline bool operator!=(const count_iterator<T>& it1, const count_iterator<T>& it2) {
74  return *it1 != *it2;
75 }
76 
77 template <typename T>
78 inline bool operator<(const count_iterator<T>& it1, const count_iterator<T>& it2) {
79  return *it1 < *it2;
80 }
81 
82 template <typename T>
83 inline bool operator>(const count_iterator<T>& it1, const count_iterator<T>& it2) {
84  return *it1 > *it2;
85 }
86 
87 template <typename T>
88 inline bool operator<=(const count_iterator<T>& it1, const count_iterator<T>& it2) {
89  return *it1 <= *it2;
90 }
91 
92 template <typename T>
93 inline bool operator>=(const count_iterator<T>& it1, const count_iterator<T>& it2) {
94  return *it1 >= *it2;
95 }
96 
97 template <typename T>
98 inline auto make_count_iterator(T x) {
99  return count_iterator(x);
100 }
101 
102 }
Count iterator.
Definition: count_iterator.hpp:33
void pointer
Definition: count_iterator.hpp:39
this_t & operator-=(difference_type diff)
Definition: count_iterator.hpp:51
this_t operator-(difference_type diff) const
Definition: count_iterator.hpp:60
count_iterator()
Definition: count_iterator.hpp:43
count_iterator(T val)
Definition: count_iterator.hpp:44
this_t & operator--()
Definition: count_iterator.hpp:54
reference operator[](difference_type diff) const
Definition: count_iterator.hpp:48
std::ptrdiff_t difference_type
Definition: count_iterator.hpp:37
this_t operator++(int)
Definition: count_iterator.hpp:56
this_t & operator+=(difference_type diff)
Definition: count_iterator.hpp:50
this_t & operator++()
Definition: count_iterator.hpp:53
std::random_access_iterator_tag iterator_category
Definition: count_iterator.hpp:41
reference operator*() const
Definition: count_iterator.hpp:46
T value_type
Definition: count_iterator.hpp:38
difference_type operator-(const this_t &it) const
Definition: count_iterator.hpp:61
this_t operator--(int)
Definition: count_iterator.hpp:57
this_t operator+(difference_type diff) const
Definition: count_iterator.hpp:59
T reference
Definition: count_iterator.hpp:40
Definition: allocator.hpp:16
bool operator==(const global_vector< T > &x, const global_vector< T > &y)
Definition: global_vector.hpp:669
bool operator<=(const unique_file_ptr< T1 > &ufp1, const unique_file_ptr< T2 > &ufp2)
Definition: unique_file_ptr.hpp:228
bool operator!=(const global_vector< T > &x, const global_vector< T > &y)
Definition: global_vector.hpp:676
bool operator>=(const unique_file_ptr< T1 > &ufp1, const unique_file_ptr< T2 > &ufp2)
Definition: unique_file_ptr.hpp:198
bool operator<(const unique_file_ptr< T1 > &ufp1, const unique_file_ptr< T2 > &ufp2)
Definition: unique_file_ptr.hpp:213
bool operator>(const unique_file_ptr< T1 > &ufp1, const unique_file_ptr< T2 > &ufp2)
Definition: unique_file_ptr.hpp:183
auto make_count_iterator(T x)
Definition: count_iterator.hpp:98