OpenMPCD
StridedPointerIteratorRange.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the OpenMPCD::StridedPointerIteratorRange class.
4  */
5 
6 #ifndef OPENMPCD_STRIDEDPOINTERITERATORRANGE_HPP
7 #define OPENMPCD_STRIDEDPOINTERITERATORRANGE_HPP
8 
11 
12 #include <boost/static_assert.hpp>
13 
14 namespace OpenMPCD
15 {
16  /**
17  * Represents a range of pointers that can be iterated over.
18  * @tparam Pointee The type the underlying pointer points at.
19  * @tparam stride The iteration stride, which must not be 0.
20  */
21  template<typename Pointee, unsigned int stride> class StridedPointerIteratorRange
22  {
23  BOOST_STATIC_ASSERT(stride != 0);
24 
25  public:
26  /**
27  * The constructor.
28  * @param[in] start_ The first element to iterate over.
29  * @param[in] numberOfElements The total number of elements in the array.
30  */
31  StridedPointerIteratorRange(Pointee* const start_, const std::size_t numberOfElements)
32  : start(start_), pastTheEnd(start + numberOfElements)
33  {
34  }
35 
36  public:
37  /**
38  * Returns the first iterator in the range.
39  */
41  {
42  return StridedPointerIterator<Pointee, stride>(start, pastTheEnd);
43  }
44 
45  /**
46  * Returns the past-the-end iterator.
47  */
49  {
50  return StridedPointerIterator<Pointee, stride>(pastTheEnd, pastTheEnd);
51  }
52 
53  private:
54  Pointee* start; ///< The first pointer in the range.
55  Pointee* pastTheEnd; ///< The first pointer that lies past the end of the range.
56  };
57 }
58 
59 #endif
OpenMPCD::StridedPointerIteratorRange::end
StridedPointerIterator< Pointee, stride > end() const
Returns the past-the-end iterator.
Definition: StridedPointerIteratorRange.hpp:48
Exceptions.hpp
OpenMPCD::StridedPointerIterator
Wraps a pointer in such a way that incrementing this iterator is equivalent to incrementing the under...
Definition: StridedPointerIterator.hpp:23
StridedPointerIterator.hpp
OpenMPCD::StridedPointerIteratorRange::begin
StridedPointerIterator< Pointee, stride > begin() const
Returns the first iterator in the range.
Definition: StridedPointerIteratorRange.hpp:40
OpenMPCD::StridedPointerIteratorRange::StridedPointerIteratorRange
StridedPointerIteratorRange(Pointee *const start_, const std::size_t numberOfElements)
The constructor.
Definition: StridedPointerIteratorRange.hpp:31
OpenMPCD::StridedPointerIteratorRange
Represents a range of pointers that can be iterated over.
Definition: StridedPointerIteratorRange.hpp:21