20 #ifndef RAJA_ITERATORS_HPP
21 #define RAJA_ITERATORS_HPP
26 #include <type_traits>
30 #include "RAJA/config.hpp"
42 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
43 template<
typename LType,
typename RType>
44 std::string overflow_msg(LType lhs, RType rhs)
46 return "Iterator Overflow detected between operation of :\n\ttype : " +
47 (std::string)
typeid(lhs).name() +
" val : " + std::to_string(lhs) +
48 "\n\ttype : " +
typeid(rhs).name() +
" val : " + std::to_string(rhs) +
52 template<
typename Type,
typename DifferenceType>
55 if (std::is_unsigned<Type>::value)
65 template<
typename Type,
typename DifferenceType>
68 bool iterator_on_left =
true)
73 if (std::is_unsigned<Type>::value)
84 if (std::is_unsigned<DifferenceType>::value)
88 if ((lhs < 0))
return true;
94 template<
typename Type,
typename DifferenceType>
95 RAJA_HOST_DEVICE void check_is_addition_overflow(Type lhs, DifferenceType rhs)
97 if (is_addition_overflow(lhs, rhs))
98 throw std::runtime_error(overflow_msg(lhs, rhs));
101 template<
typename Type,
typename DifferenceType>
105 if (is_subtraction_overflow(lhs, rhs))
106 throw std::runtime_error(overflow_msg(lhs, rhs));
111 typename DifferenceType = Type,
112 typename PointerType = Type*>
137 return val == rhs.val;
142 return val != rhs.val;
147 return val > rhs.val;
152 return val < rhs.val;
157 return val >= rhs.val;
162 return val <= rhs.val;
194 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
195 check_is_addition_overflow(val, rhs);
204 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
205 check_is_subtraction_overflow(val, rhs);
228 return val + rhs.val;
234 return val - rhs.val;
240 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
241 check_is_addition_overflow(val, rhs);
249 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
250 check_is_subtraction_overflow(val, rhs);
259 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
260 return is_addition_overflow(rhs.val, lhs)
261 ?
throw std::runtime_error(overflow_msg(lhs, rhs.val))
272 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
273 return is_subtraction_overflow(rhs.val, lhs,
false)
274 ?
throw std::runtime_error(overflow_msg(lhs, rhs.val))
301 typename DifferenceType = Type,
302 typename PointerType = Type*>
325 DifferenceType stride_ = DifferenceType(1))
347 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
348 check_is_addition_overflow(val, rhs * stride);
357 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
358 check_is_subtraction_overflow(val, rhs * stride);
386 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
387 check_is_addition_overflow(val, rhs * stride);
395 #if defined(RAJA_ENABLE_ITERATOR_OVERFLOW_DEBUG)
396 check_is_subtraction_overflow(val, rhs * stride);
406 return (val - rhs.val) / stride;
412 return !((val - rhs.val) / stride);
418 return val * stride > rhs.val * stride;
424 return val * stride < rhs.val * stride;
430 return val * stride >= rhs.val * stride;
436 return val * stride <= rhs.val * stride;
456 DifferenceType stride = 1;
RAJA header file for strongly-typed integer class.
Definition: Iterators.hpp:114
RAJA_HOST_DEVICE numeric_iterator & operator-=(const numeric_iterator &rhs)
Definition: Iterators.hpp:218
RAJA_HOST_DEVICE bool operator!=(const numeric_iterator &rhs) const
Definition: Iterators.hpp:140
RAJA_HOST_DEVICE stripped_value_type operator-(const numeric_iterator &rhs) const
Definition: Iterators.hpp:231
RAJA_HOST_DEVICE numeric_iterator & operator++()
Definition: Iterators.hpp:165
RAJA_HOST_DEVICE numeric_iterator operator-(const difference_type &rhs) const
Definition: Iterators.hpp:246
RAJA_HOST_DEVICE numeric_iterator & operator--()
Definition: Iterators.hpp:171
RAJA_HOST_DEVICE value_type operator->() const
Definition: Iterators.hpp:286
RAJA_HOST_DEVICE value_type operator*() const
Definition: Iterators.hpp:281
PointerType pointer
Definition: Iterators.hpp:119
constexpr RAJA_HOST_DEVICE value_type operator[](difference_type rhs) const
Definition: Iterators.hpp:291
RAJA_HOST_DEVICE constexpr friend numeric_iterator operator+(difference_type lhs, const numeric_iterator &rhs)
Definition: Iterators.hpp:255
RAJA_HOST_DEVICE numeric_iterator & operator+=(const difference_type &rhs)
Definition: Iterators.hpp:191
Type value_type
Definition: Iterators.hpp:116
strip_index_type_t< Type > stripped_value_type
Definition: Iterators.hpp:117
RAJA_HOST_DEVICE constexpr friend numeric_iterator operator-(difference_type lhs, const numeric_iterator &rhs)
Definition: Iterators.hpp:268
value_type & reference
Definition: Iterators.hpp:120
constexpr numeric_iterator() noexcept=default
RAJA_HOST_DEVICE numeric_iterator operator--(int)
Definition: Iterators.hpp:184
RAJA_HOST_DEVICE bool operator<(const numeric_iterator &rhs) const
Definition: Iterators.hpp:150
RAJA_HOST_DEVICE bool operator>(const numeric_iterator &rhs) const
Definition: Iterators.hpp:145
RAJA_HOST_DEVICE DifferenceType get_stride() const
Definition: Iterators.hpp:133
RAJA_HOST_DEVICE numeric_iterator operator++(int)
Definition: Iterators.hpp:177
RAJA_HOST_DEVICE numeric_iterator & operator+=(const numeric_iterator &rhs)
Definition: Iterators.hpp:211
RAJA_HOST_DEVICE bool operator==(const numeric_iterator &rhs) const
Definition: Iterators.hpp:135
DifferenceType difference_type
Definition: Iterators.hpp:118
std::random_access_iterator_tag iterator_category
Definition: Iterators.hpp:121
RAJA_HOST_DEVICE bool operator>=(const numeric_iterator &rhs) const
Definition: Iterators.hpp:155
RAJA_HOST_DEVICE numeric_iterator operator+(const difference_type &rhs) const
Definition: Iterators.hpp:237
RAJA_HOST_DEVICE bool operator<=(const numeric_iterator &rhs) const
Definition: Iterators.hpp:160
RAJA_HOST_DEVICE numeric_iterator & operator-=(const difference_type &rhs)
Definition: Iterators.hpp:201
RAJA_HOST_DEVICE stripped_value_type operator+(const numeric_iterator &rhs) const
Definition: Iterators.hpp:225
Definition: Iterators.hpp:304
strip_index_type_t< Type > stripped_value_type
Definition: Iterators.hpp:307
Type value_type
Definition: Iterators.hpp:306
RAJA_HOST_DEVICE strided_numeric_iterator & operator++()
Definition: Iterators.hpp:332
RAJA_HOST_DEVICE DifferenceType get_stride() const
Definition: Iterators.hpp:330
std::random_access_iterator_tag iterator_category
Definition: Iterators.hpp:311
RAJA_HOST_DEVICE bool operator<(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:421
RAJA_HOST_DEVICE strided_numeric_iterator operator+(const difference_type &rhs) const
Definition: Iterators.hpp:383
RAJA_HOST_DEVICE bool operator!=(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:403
RAJA_HOST_DEVICE bool operator==(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:409
RAJA_HOST_DEVICE bool operator>=(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:427
RAJA_HOST_DEVICE value_type operator->() const
Definition: Iterators.hpp:444
constexpr strided_numeric_iterator() noexcept=default
RAJA_HOST_DEVICE bool operator>(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:415
constexpr RAJA_HOST_DEVICE value_type operator[](difference_type rhs) const
Definition: Iterators.hpp:449
RAJA_HOST_DEVICE strided_numeric_iterator operator-(const difference_type &rhs) const
Definition: Iterators.hpp:392
DifferenceType * pointer
Definition: Iterators.hpp:309
RAJA_HOST_DEVICE difference_type operator+(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:364
DifferenceType & reference
Definition: Iterators.hpp:310
RAJA_HOST_DEVICE bool operator<=(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:433
RAJA_HOST_DEVICE strided_numeric_iterator & operator-=(const difference_type &rhs)
Definition: Iterators.hpp:354
RAJA_HOST_DEVICE value_type operator*() const
Definition: Iterators.hpp:439
RAJA_HOST_DEVICE strided_numeric_iterator & operator--()
Definition: Iterators.hpp:338
DifferenceType difference_type
Definition: Iterators.hpp:308
RAJA_HOST_DEVICE strided_numeric_iterator & operator+=(const difference_type &rhs)
Definition: Iterators.hpp:344
RAJA_HOST_DEVICE difference_type operator-(const strided_numeric_iterator &rhs) const
Definition: Iterators.hpp:372
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result min(Args... args)
Definition: foldl.hpp:161
std::ptrdiff_t Index_type
Definition: types.hpp:226
typename internal::StripIndexTypeT< FROM >::type strip_index_type_t
Strips a strongly typed index to its underlying type In the case of a non-strongly typed index,...
Definition: IndexValue.hpp:364
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result max(Args... args)
Definition: foldl.hpp:155
Header file for RAJA type definitions.