quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
Loading...
Searching...
No Matches
counter.h
Go to the documentation of this file.
1#ifndef HAVE_COUNTER_H
2#define HAVE_COUNTER_H
3
4#include <iterator>
5
6template <typename N>
7struct range {
8
9 struct
10 iterator {
11 friend class range;
12 using difference_type = typename std::make_signed_t<N>;
13 using iterator_category = std::random_access_iterator_tag;
14 using value_type = N;
15 using reference = N;
16 using pointer = const N*;
17 iterator &operator ++() { ++i_; return *this; }
18 iterator operator ++(int) { iterator copy(*this); ++i_; return copy; }
19 reference operator *() const { return i_; }
20 bool operator ==(const iterator &other) const { return i_ == *other; }
21 bool operator !=(const iterator &other) const { return i_ != *other; }
22
23 bool operator <(const iterator &other) const { return i_ < *other; }
24 difference_type operator -(const iterator &other) const { return static_cast<difference_type>(i_) - static_cast<difference_type>(*other); }
25 iterator operator -(const difference_type other) const { return iterator (static_cast<value_type> (static_cast<difference_type>(i_) - other)); }
26 iterator operator +(const difference_type other) const { return iterator (static_cast<value_type> (static_cast<difference_type>(i_) + other)); }
27 value_type operator[] (const value_type& idx) { return i_ + idx; }
28 protected: explicit iterator(difference_type start) : i_ (start) {};
29 private:
30 N i_;
31 };
32
33 iterator begin () const { return begin_; }
34 iterator end () const { return end_; }
36
37private:
39};
40
41#endif
Definition counter.h:10
iterator(difference_type start)
Definition counter.h:28
N value_type
Definition counter.h:14
N reference
Definition counter.h:15
const N * pointer
Definition counter.h:16
N i_
Definition counter.h:30
std::random_access_iterator_tag iterator_category
Definition counter.h:13
friend class range
Definition counter.h:11
typename std::make_signed_t< N > difference_type
Definition counter.h:12
iterator begin() const
Definition counter.h:33
range(N begin, N end)
Definition counter.h:35
iterator end_
Definition counter.h:38
iterator begin_
Definition counter.h:38
iterator end() const
Definition counter.h:34