DUDS
Distributed Update of Data from Something
IntegerBiDirIterator.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 #ifndef INTEGERBIDIRITERATOR_HPP
11 #define INTEGERBIDIRITERATOR_HPP
12 
13 #include <iterator>
14 
15 namespace duds { namespace general {
16 
22 template <typename Int>
24  Int val;
25 public:
26  typedef std::bidirectional_iterator_tag iterator_category;
27  typedef Int value_type;
28  typedef int difference_type;
29  typedef value_type* pointer;
30  typedef value_type& reference;
31  IntegerBiDirIterator() = default;
32  IntegerBiDirIterator(Int i) : val(i) { }
34  ++val;
35  return *this;
36  }
38  return IntegerBiDirIterator(val++);
39  }
41  --val;
42  return *this;
43  }
45  return IntegerBiDirIterator(val--);
46  }
47  Int operator * () const {
48  return val;
49  }
50  bool operator != (const IntegerBiDirIterator &i) const {
51  return val != i.val;
52  }
53 };
54 
55 } }
56 
57 #endif // #ifndef INTEGERBIDIRITERATOR_HPP
std::bidirectional_iterator_tag iterator_category
A bidirectional iterator intended to work with sequential integers.
bool operator!=(const IntegerBiDirIterator &i) const