DASH  0.3.0
Iterator.h
1 #ifndef DASH__ITERATOR_H__INCLUDED
2 #define DASH__ITERATOR_H__INCLUDED
3 
4 #include <dash/Types.h>
5 #include <dash/Dimensional.h>
6 #include <dash/iterator/IteratorTraits.h>
7 #include <dash/iterator/GlobIter.h>
8 #include <dash/iterator/GlobViewIter.h>
9 
10 #include <iterator>
11 
50 namespace dash {
51 
52 
57 template <class IndexType>
58 constexpr typename std::enable_if<
59  std::is_integral<IndexType>::value, IndexType >::type
60 index(IndexType idx) {
61  return idx;
62 }
63 
68 // template <class Iterator>
69 // constexpr auto index(Iterator it) -> decltype((++it).pos()) {
70 // return it.pos();
71 // }
72 
77 template <class Iterator>
78 constexpr auto index(Iterator it) -> decltype((++it).gpos()) {
79  return it.gpos();
80 }
81 
82 
88 template <class RandomAccessIt>
89 typename RandomAccessIt::difference_type
91  const RandomAccessIt & first,
92  const RandomAccessIt & last)
93 {
94  return last - first;
95 }
96 
123 template<
124  typename ElementType,
125  class Pattern,
126  class GlobMemType,
127  class Pointer,
128  class Reference >
129 typename Pattern::index_type
133  first,
136  last)
137 {
138  return last - first;
139 }
140 
141 template<
142  typename ElementType,
143  class Pattern,
144  class GlobMemType,
145  class Pointer,
146  class Reference >
147 DASH_CONSTEXPR auto operator-(
150  lhs,
153  rhs) DASH_NOEXCEPT
154 {
155  return lhs.pos() - rhs.pos();
156 }
157 
164 template <class T>
165 constexpr std::ptrdiff_t distance(T * const first, T * const last) {
166  return std::distance(first, last);
167 }
168 
175 template <
176  class OffsetType >
177 constexpr typename std::enable_if<
178  std::is_integral<OffsetType>::value,
179  OffsetType >::type
181  OffsetType begin,
182  OffsetType end) {
183  return (end - begin);
184 }
185 
186 } // namespace dash
187 
188 #endif // DASH__ITERATOR_H__INCLUDED
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
Definition: Range.h:98
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
Definition: Range.h:89
dash::BlockPattern< NumDimensions, Arrangement, IndexType > Pattern
Template alias for dash::Pattern with the same default template arguments.
Definition: Pattern.h:644
DASH_CONSTEXPR auto operator-(const GlobIter< ElementType, Pattern, GlobMemType, Pointer, Reference > &lhs, const GlobIter< ElementType, Pattern, GlobMemType, Pointer, Reference > &rhs) DASH_NOEXCEPT
Definition: Iterator.h:147
Returns second operand.
Definition: Operation.h:201
Iterator on Partitioned Global Address Space.
Definition: GlobIter.h:45
constexpr std::enable_if< std::is_integral< OffsetType >::value, OffsetType >::type distance(OffsetType begin, OffsetType end)
Definition: Iterator.h:180
dash::gptrdiff_t distance(GlobPtr< T, MemSpaceT > gbegin, GlobPtr< T, MemSpaceT > gend)
Returns the number of hops from gbegin to gend.
Definition: GlobPtr.h:547