Libsaki
Core library of Pancake Mahjong
int_iter.h
1 #ifndef SAKI_INT_ITER_H
2 #define SAKI_INT_ITER_H
3 
4 #include <iterator>
5 
6 
7 
8 namespace saki
9 {
10 
11 
12 
13 template<typename T>
14 class IntIter
15 {
16 public:
17  constexpr explicit IntIter(int c) : mCurr(c) {}
18 
19  // std input iterator traits
20  using iterator_category = std::input_iterator_tag;
21  using difference_type = int;
22  using value_type = T;
23  using pointer = T *;
24  using reference = T &;
25 
26  T operator*()
27  {
28  return T(mCurr);
29  }
30 
31  IntIter &operator++() noexcept
32  {
33  ++mCurr;
34  return *this;
35  }
36 
37  bool operator==(IntIter that) const noexcept
38  {
39  return mCurr == that.mCurr;
40  }
41 
42  bool operator!=(IntIter that) const noexcept
43  {
44  return !(*this == that);
45  }
46 
47 private:
48  int mCurr;
49 };
50 
51 
52 
53 template<typename T, int END>
54 class IntRange
55 {
56 public:
57  using iterator = IntIter<T>;
58  using value_type = T;
59 
60  constexpr IntIter<T> begin() const
61  {
62  return IntIter<T>(0);
63  }
64 
65  constexpr IntIter<T> end() const
66  {
67  return IntIter<T>(END);
68  }
69 };
70 
71 
72 
73 } // namespace saki
74 
75 
76 
77 #endif // SAKI_INT_ITER_H
Definition: int_iter.h:14
Definition: int_iter.h:54
Definition: ai.cpp:18