10 #ifndef vtk_m_cont_internal_ArrayPortalFromIterators_h
11 #define vtk_m_cont_internal_ArrayPortalFromIterators_h
22 #include <type_traits>
31 template <
typename IteratorT,
typename Enable =
void>
32 class ArrayPortalFromIterators;
37 template <
class IteratorT>
38 class ArrayPortalFromIterators<IteratorT,
39 typename std::enable_if<!std::is_const<
40 typename std::remove_pointer<IteratorT>::type>::value>::type>
43 using ValueType =
typename std::iterator_traits<IteratorT>::value_type;
44 using IteratorType = IteratorT;
46 ArrayPortalFromIterators() =
default;
50 ArrayPortalFromIterators(IteratorT begin, IteratorT end)
51 : BeginIterator(begin)
53 typename std::iterator_traits<IteratorT>::difference_type numberOfValues =
54 std::distance(begin, end);
56 #ifndef VTKM_USE_64BIT_IDS
57 if (numberOfValues > (std::numeric_limits<vtkm::Id>::max)())
60 "Distance of iterators larger than maximum array size. "
61 "To support larger arrays, try turning on VTKM_USE_64BIT_IDS.");
63 #endif // !VTKM_USE_64BIT_IDS
64 this->NumberOfValues =
static_cast<vtkm::Id>(numberOfValues);
71 template <
class OtherIteratorT>
72 VTKM_EXEC_CONT ArrayPortalFromIterators(
const ArrayPortalFromIterators<OtherIteratorT>& src)
73 : BeginIterator(src.GetIteratorBegin())
74 , NumberOfValues(src.GetNumberOfValues())
80 vtkm::Id GetNumberOfValues()
const {
return this->NumberOfValues; }
84 ValueType
Get(
vtkm::Id index)
const {
return *this->IteratorAt(index); }
88 void Set(
vtkm::Id index,
const ValueType& value)
const { *(this->BeginIterator + index) = value; }
92 IteratorT GetIteratorBegin()
const {
return this->BeginIterator; }
96 IteratorT GetIteratorEnd()
const
98 IteratorType iterator = this->BeginIterator;
99 using difference_type =
typename std::iterator_traits<IteratorType>::difference_type;
100 iterator +=
static_cast<difference_type
>(this->NumberOfValues);
105 IteratorT BeginIterator;
110 IteratorT IteratorAt(
vtkm::Id index)
const
115 return this->BeginIterator + index;
119 template <
class IteratorT>
120 class ArrayPortalFromIterators<IteratorT,
121 typename std::enable_if<std::is_const<
122 typename std::remove_pointer<IteratorT>::type>::value>::type>
125 using ValueType =
typename std::iterator_traits<IteratorT>::value_type;
126 using IteratorType = IteratorT;
130 ArrayPortalFromIterators()
131 : BeginIterator(nullptr)
138 ArrayPortalFromIterators(IteratorT begin, IteratorT end)
139 : BeginIterator(begin)
141 typename std::iterator_traits<IteratorT>::difference_type numberOfValues =
142 std::distance(begin, end);
144 #ifndef VTKM_USE_64BIT_IDS
145 if (numberOfValues > (std::numeric_limits<vtkm::Id>::max)())
148 "Distance of iterators larger than maximum array size. "
149 "To support larger arrays, try turning on VTKM_USE_64BIT_IDS.");
151 #endif // !VTKM_USE_64BIT_IDS
152 this->NumberOfValues =
static_cast<vtkm::Id>(numberOfValues);
160 template <
class OtherIteratorT>
161 VTKM_EXEC_CONT ArrayPortalFromIterators(
const ArrayPortalFromIterators<OtherIteratorT>& src)
162 : BeginIterator(src.GetIteratorBegin())
163 , NumberOfValues(src.GetNumberOfValues())
169 vtkm::Id GetNumberOfValues()
const {
return this->NumberOfValues; }
173 ValueType
Get(
vtkm::Id index)
const {
return *this->IteratorAt(index); }
177 IteratorT GetIteratorBegin()
const {
return this->BeginIterator; }
181 IteratorT GetIteratorEnd()
const
183 using difference_type =
typename std::iterator_traits<IteratorType>::difference_type;
184 IteratorType iterator = this->BeginIterator;
185 iterator +=
static_cast<difference_type
>(this->NumberOfValues);
190 IteratorT BeginIterator;
195 IteratorT IteratorAt(
vtkm::Id index)
const
200 return this->BeginIterator + index;
207 #endif //vtk_m_cont_internal_ArrayPortalFromIterators_h