autoppl  v0.8
A C++ template library for probabilistic programming
counting_iterator.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <cstdint>
3 #include <iterator>
4 
5 namespace ppl {
6 namespace util {
7 
8 // forward declaration
9 template <class IntType>
10 struct counting_iterator;
11 
12 template <class IntType>
13 inline constexpr bool
15  const counting_iterator<IntType>& it2)
16 { return it1.curr_ == it2.curr_; }
17 
18 template <class IntType>
19 inline constexpr bool
21  const counting_iterator<IntType>& it2)
22 { return it1.curr_ != it2.curr_; }
23 
24 template <class IntType=uint32_t>
26 {
27  using difference_type = int32_t;
28  using value_type = IntType;
29  using pointer = value_type*;
30  using reference = IntType&;
31  using iterator_category = std::bidirectional_iterator_tag;
32 
34  : curr_(begin)
35  {}
36 
37  counting_iterator& operator++() { ++curr_; return *this; }
38  counting_iterator& operator--() { --curr_; return *this; }
39  counting_iterator operator++(int) { auto tmp = *this; ++curr_; return tmp; }
40  counting_iterator operator--(int) { auto tmp = *this; --curr_; return tmp; }
41  reference operator*() { return curr_; }
42 
43  friend constexpr bool operator==<>(const counting_iterator&,
44  const counting_iterator&);
45  friend constexpr bool operator!=<>(const counting_iterator&,
46  const counting_iterator&);
47 private:
48  value_type curr_;
49 };
50 
51 } // namespace util
52 } // namespace ppl
ppl::util::counting_iterator::value_type
IntType value_type
Definition: counting_iterator.hpp:28
ppl::util::counting_iterator::operator--
counting_iterator operator--(int)
Definition: counting_iterator.hpp:40
ppl::util::counting_iterator::operator++
counting_iterator operator++(int)
Definition: counting_iterator.hpp:39
ppl::util::operator!=
constexpr bool operator!=(const counting_iterator< IntType > &it1, const counting_iterator< IntType > &it2)
Definition: counting_iterator.hpp:20
ppl::util::counting_iterator::counting_iterator
counting_iterator(value_type begin)
Definition: counting_iterator.hpp:33
ppl::util::operator==
constexpr bool operator==(const counting_iterator< IntType > &it1, const counting_iterator< IntType > &it2)
Definition: counting_iterator.hpp:14
ppl::util::counting_iterator::operator++
counting_iterator & operator++()
Definition: counting_iterator.hpp:37
ppl::util::counting_iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: counting_iterator.hpp:31
ppl::util::counting_iterator
Definition: counting_iterator.hpp:26
ppl::util::counting_iterator::difference_type
int32_t difference_type
Definition: counting_iterator.hpp:27
ppl
Definition: bounded.hpp:11
ppl::util::counting_iterator::reference
IntType & reference
Definition: counting_iterator.hpp:30
ppl::util::counting_iterator::operator*
reference operator*()
Definition: counting_iterator.hpp:41
ppl::util::counting_iterator::operator--
counting_iterator & operator--()
Definition: counting_iterator.hpp:38
ppl::util::counting_iterator::pointer
value_type * pointer
Definition: counting_iterator.hpp:29