ArmNN
 24.02
TransformIterator.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020,2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <iterator>
8 
9 namespace armnn
10 {
11 template<typename Function,
12  typename Iterator,
13  typename Category = typename std::iterator_traits<Iterator>::iterator_category,
14  typename T = typename std::iterator_traits<Iterator>::value_type,
15  typename Distance = typename std::iterator_traits<Iterator>::difference_type,
16  typename Pointer = typename std::iterator_traits<Iterator>::pointer,
17 #if __cplusplus < 201703
18  typename Reference =
19  typename std::result_of<const Function(typename std::iterator_traits<Iterator>::reference)>::type
20 #else
21  typename Reference =
22  typename std::invoke_result<const Function, typename std::iterator_traits<Iterator>::reference>::type
23 #endif
24 >
26 {
27 public:
28  using iterator_category = Category;
29  using value_type = T;
30  using difference_type = Distance;
31  using pointer = Pointer;
32  using reference = Reference;
33 
34 
35  TransformIterator() = default;
36  TransformIterator(TransformIterator const& transformIterator) = default;
37  TransformIterator(TransformIterator&& transformIterator) = default;
38 
39  TransformIterator(Iterator& it, Function fn) : m_it(it), m_fn(fn) {}
40  TransformIterator(Iterator&& it, Function fn) : m_it(it), m_fn(fn) {}
41 
42  ~TransformIterator() = default;
43 
45  {
46  m_fn = rhs.m_fn;
47  m_it = rhs.m_it;
48  return *this;
49  }
50 
52  {
53  m_fn = std::move(rhs.m_fn);
54  m_it = std::move(rhs.m_it);
55  return *this;
56  }
57 
58  TransformIterator operator++() {++m_it; return *this;}
59  TransformIterator operator--() {--m_it; return *this;}
60 
61  TransformIterator operator++() const {++m_it; return *this;}
62  TransformIterator operator--() const {--m_it; return *this;}
63 
64  TransformIterator operator++(int n) const {m_it += n; return *this;}
65  TransformIterator operator--(int n) const {m_it -= n; return *this;}
66 
67  TransformIterator operator[](Distance n) const {m_it[n]; return *this;};
68 
69  Distance operator-(const TransformIterator& other) {return m_it - other.m_it;}
70 
71  TransformIterator operator-(const Distance n) {return {m_it - n, m_fn};}
72  TransformIterator operator+(const Distance n) {return {m_it + n, m_fn};}
73 
74  bool operator>(const TransformIterator& rhs) const {return m_it > rhs.m_it;}
75  bool operator<(const TransformIterator& rhs) const {return m_it < rhs.m_it;}
76  bool operator>=(const TransformIterator& rhs) const {return m_it >= rhs.m_it;}
77  bool operator<=(const TransformIterator& rhs) const {return m_it <= rhs.m_it;}
78 
79  bool operator==(TransformIterator other) const {return (m_it == other.m_it);}
80  bool operator!=(TransformIterator other) const {return (m_it != other.m_it);}
81 
82  Reference operator*() const {return m_fn(*m_it);}
83 
84 private:
85  Iterator m_it;
86  Function m_fn;
87 };
88 
89 template<typename Function, typename Iterator>
91 {
93 }
94 
95 }
armnn::TransformIterator::reference
Reference reference
Definition: TransformIterator.hpp:32
armnn::TransformIterator::operator-
Distance operator-(const TransformIterator &other)
Definition: TransformIterator.hpp:69
armnn::TransformIterator::operator--
TransformIterator operator--(int n) const
Definition: TransformIterator.hpp:65
armnn::TransformIterator::operator=
TransformIterator & operator=(TransformIterator const &rhs)
Definition: TransformIterator.hpp:44
armnn::TransformIterator::difference_type
Distance difference_type
Definition: TransformIterator.hpp:30
armnn::TransformIterator::operator*
Reference operator*() const
Definition: TransformIterator.hpp:82
armnn::TransformIterator::~TransformIterator
~TransformIterator()=default
armnn::TransformIterator::operator<
bool operator<(const TransformIterator &rhs) const
Definition: TransformIterator.hpp:75
armnn::MakeTransformIterator
constexpr TransformIterator< Function, Iterator > MakeTransformIterator(Iterator i, Function f)
Definition: TransformIterator.hpp:90
armnn::TransformIterator::operator>=
bool operator>=(const TransformIterator &rhs) const
Definition: TransformIterator.hpp:76
armnn::TransformIterator::operator<=
bool operator<=(const TransformIterator &rhs) const
Definition: TransformIterator.hpp:77
armnn::TransformIterator::operator++
TransformIterator operator++()
Definition: TransformIterator.hpp:58
armnn::TransformIterator::operator++
TransformIterator operator++() const
Definition: TransformIterator.hpp:61
armnn::TransformIterator::operator--
TransformIterator operator--()
Definition: TransformIterator.hpp:59
armnn::TransformIterator::operator[]
TransformIterator operator[](Distance n) const
Definition: TransformIterator.hpp:67
armnn::TransformIterator::operator=
TransformIterator & operator=(TransformIterator &&rhs)
Definition: TransformIterator.hpp:51
armnn::TransformIterator::value_type
T value_type
Definition: TransformIterator.hpp:29
armnn::TransformIterator::operator>
bool operator>(const TransformIterator &rhs) const
Definition: TransformIterator.hpp:74
armnn::TransformIterator::operator--
TransformIterator operator--() const
Definition: TransformIterator.hpp:62
armnn::TransformIterator::TransformIterator
TransformIterator()=default
armnn::TransformIterator::operator++
TransformIterator operator++(int n) const
Definition: TransformIterator.hpp:64
armnn::TransformIterator::TransformIterator
TransformIterator(Iterator &it, Function fn)
Definition: TransformIterator.hpp:39
armnn::TransformIterator::TransformIterator
TransformIterator(Iterator &&it, Function fn)
Definition: TransformIterator.hpp:40
armnn::TransformIterator::operator!=
bool operator!=(TransformIterator other) const
Definition: TransformIterator.hpp:80
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::TransformIterator::operator+
TransformIterator operator+(const Distance n)
Definition: TransformIterator.hpp:72
armnn::TransformIterator::operator==
bool operator==(TransformIterator other) const
Definition: TransformIterator.hpp:79
armnn::TransformIterator::operator-
TransformIterator operator-(const Distance n)
Definition: TransformIterator.hpp:71
armnn::TransformIterator::pointer
Pointer pointer
Definition: TransformIterator.hpp:31
armnn::TransformIterator::iterator_category
Category iterator_category
Definition: TransformIterator.hpp:28
armnn::TransformIterator
Definition: TransformIterator.hpp:25