libMesh
int_range.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_INT_RANGE_H
21 #define LIBMESH_INT_RANGE_H
22 
23 // C++ Includes -----------------------------------
24 #include <map>
25 
26 namespace libMesh
27 {
28 
41 template <typename T>
42 class IntRange
43 {
44 public:
45  class iterator {
46  public:
47  iterator (T i) : _i(i) {}
48 
49  T operator* () const { return _i; }
50 
51  const iterator & operator++ () {
52  ++_i;
53  return *this;
54  }
55 
57  iterator returnval(*this);
58  ++_i;
59  return returnval;
60  }
61 
62  bool operator== (const iterator & j) const {
63  return ( _i == j._i );
64  }
65 
66  bool operator!= (const iterator & j) const {
67  return !(*this == j);
68  }
69 
70  private:
71  T _i;
72  };
73 
74  IntRange(T begin, T end) : _begin(begin), _end(end) {}
75 
76  iterator begin() const { return _begin; }
77 
78  iterator end () const { return _end; }
79 
80 private:
82 };
83 
84 } // namespace libMesh
85 
86 #endif // LIBMESH_INT_RANGE_H
iterator _begin
Definition: int_range.h:81
IntRange(T begin, T end)
Definition: int_range.h:74
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition: int_range.h:42
iterator begin() const
Definition: int_range.h:76
iterator end() const
Definition: int_range.h:78
The libMesh namespace provides an interface to certain functionality in the library.
bool operator!=(const iterator &j) const
Definition: int_range.h:66
const iterator & operator++()
Definition: int_range.h:51
bool operator==(const iterator &j) const
Definition: int_range.h:62
iterator _end
Definition: int_range.h:81