10#ifndef XTENSOR_XMULTIINDEX_ITERATOR
11#define XTENSOR_XMULTIINDEX_ITERATOR
13#include "xstrided_view.hpp"
14#include "xtl/xsequence.hpp"
20 class xmultiindex_iterator
24 using self_type = xmultiindex_iterator<S>;
27 using value_type = shape_type;
28 using reference = value_type&;
29 using pointer = value_type*;
30 using difference_type = std::size_t;
31 using iterator_category = std::forward_iterator_tag;
33 xmultiindex_iterator() =
default;
35 template <
class B,
class E,
class C>
36 xmultiindex_iterator(B&& begin, E&& end, C&& current,
const std::size_t linear_index)
37 : m_begin(std::forward<B>(begin))
38 , m_end(std::forward<E>(end))
39 , m_current(std::forward<C>(current))
40 , m_linear_index(linear_index)
44 self_type& operator++()
46 std::size_t i = m_begin.size();
50 if (m_current[i] + 1u == m_end[i])
52 m_current[i] = m_begin[i];
64 self_type operator++(
int)
71 shape_type& operator*()
76 const shape_type& operator*()
const
81 bool operator==(
const self_type& rhs)
const
83 return m_linear_index == rhs.m_linear_index;
86 bool operator!=(
const self_type& rhs)
const
88 return !this->operator==(rhs);
96 std::size_t m_linear_index{0};
99 template <
class S,
class B,
class E>
100 auto multiindex_iterator_begin(B&& roi_begin, E&& roi_end)
103 resize_container(current, roi_begin.size());
104 std::copy(roi_begin.begin(), roi_begin.end(), current.begin());
108 template <
class S,
class B,
class E>
109 auto multiindex_iterator_end(B&& roi_begin, E&& roi_end)
112 resize_container(current, roi_begin.size());
113 std::copy(roi_end.begin(), roi_end.end(), current.begin());
115 std::size_t linear_index = 1;
116 for (std::size_t i = 0; i < roi_begin.size(); ++i)
118 linear_index *= roi_end[i] - roi_begin[i];
122 std::forward<B>(roi_begin),
123 std::forward<E>(roi_end),
standard mathematical functions for xexpressions