14#include <lagrange/utils/safe_cast.h>
29 using iterator_category = std::input_iterator_tag;
31 using difference_type = std::ptrdiff_t;
36template <
typename T,
typename Trait = IteratorTrait<T>>
52 using iterator_category =
typename Trait::iterator_category;
53 using value_type =
typename Trait::value_type;
54 using difference_type =
typename Trait::difference_type;
55 using pointer =
typename Trait::pointer;
56 using reference =
typename Trait::reference;
59 explicit iterator(T val,
const Range<T>& c)
64 const T& operator*()
const {
return m_value; }
66 iterator& operator++()
74 if (m_context == other.m_context) {
75 return m_value < other.m_value;
83 const Range<T>& m_context;
86 iterator begin()
const {
return iterator(m_begin, *
this); }
88 iterator end()
const {
return iterator(m_end, *
this); }
92 return m_begin == other.m_begin && m_end == other.m_end;
100template <
typename T,
typename Trait = IteratorTrait<T>>
104 const std::vector<T>& m_active;
107 SparseRange(T max,
const std::vector<T>& active)
115 using iterator_category =
typename Trait::iterator_category;
116 using value_type =
typename Trait::value_type;
117 using difference_type =
typename Trait::difference_type;
118 using pointer =
typename Trait::pointer;
119 using reference =
typename Trait::reference;
122 iterator(T val,
const SparseRange& context)
129 return (m_context != rhs.m_context) || (i != rhs.i);
132 iterator& operator++()
140 if (m_context.m_active.empty())
return i;
141 return m_context.m_active[i];
145 const SparseRange& m_context;
149 iterator begin()
const {
return iterator(0, *
this); }
152 return iterator(m_active.empty() ? m_max : safe_cast<T>(m_active.size()), *
this);
155 bool operator!=(
const SparseRange<T> other)
const
157 return m_max != other.m_max || m_active.size() != other.m_active.size();
175template <
typename Index>
176internal::Range<Index>
range(Index end)
178 return internal::Range<Index>(end);
191template <
typename Index>
192internal::Range<Index>
range(Index begin, Index end)
194 return internal::Range<Index>(begin, end);
216template <
typename Index>
217internal::SparseRange<Index>
range_sparse(Index max,
const std::vector<Index>& active)
219 return internal::SparseRange<Index>(max, active);
228internal::SparseRange<T>
range_sparse(T , std::vector<T>&& ) =
delete;
internal::SparseRange< Index > range_sparse(Index max, const std::vector< Index > &active)
Returns an iterable object representing a subset of the range [0, max).
Definition: range.h:217
internal::Range< Index > range(Index end)
Returns an iterable object representing the range [0, end).
Definition: range.h:176
bool operator==(const shared_ptr< T > &sp1, const shared_ptr< U > &sp2)
Operator == overloading.
Definition: shared_ptr.h:344
bool operator!=(const shared_ptr< T > &sp1, const shared_ptr< U > &sp2)
Operator != overloading.
Definition: shared_ptr.h:363
Main namespace for Lagrange.
Definition: AABBIGL.h:30