1 | // -*- C++ -*-
|
---|
2 |
|
---|
3 | // Copyright (C) 2007-2021 Free Software Foundation, Inc.
|
---|
4 | //
|
---|
5 | // This file is part of the GNU ISO C++ Library. This library is free
|
---|
6 | // software; you can redistribute it and/or modify it under the terms
|
---|
7 | // of the GNU General Public License as published by the Free Software
|
---|
8 | // Foundation; either version 3, or (at your option) any later
|
---|
9 | // version.
|
---|
10 |
|
---|
11 | // This library is distributed in the hope that it will be useful, but
|
---|
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | // General Public License for more details.
|
---|
15 |
|
---|
16 | // Under Section 7 of GPL version 3, you are granted additional
|
---|
17 | // permissions described in the GCC Runtime Library Exception, version
|
---|
18 | // 3.1, as published by the Free Software Foundation.
|
---|
19 |
|
---|
20 | // You should have received a copy of the GNU General Public License and
|
---|
21 | // a copy of the GCC Runtime Library Exception along with this program;
|
---|
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
---|
23 | // <http://www.gnu.org/licenses/>.
|
---|
24 |
|
---|
25 | /** @file parallel/iterator.h
|
---|
26 | * @brief Helper iterator classes for the std::transform() functions.
|
---|
27 | * This file is a GNU parallel extension to the Standard C++ Library.
|
---|
28 | */
|
---|
29 |
|
---|
30 | // Written by Johannes Singler.
|
---|
31 |
|
---|
32 | #ifndef _GLIBCXX_PARALLEL_ITERATOR_H
|
---|
33 | #define _GLIBCXX_PARALLEL_ITERATOR_H 1
|
---|
34 |
|
---|
35 | #include <parallel/basic_iterator.h>
|
---|
36 | #include <bits/stl_pair.h>
|
---|
37 |
|
---|
38 | namespace __gnu_parallel
|
---|
39 | {
|
---|
40 | /** @brief A pair of iterators. The usual iterator operations are
|
---|
41 | * applied to both child iterators.
|
---|
42 | */
|
---|
43 | template<typename _Iterator1, typename _Iterator2,
|
---|
44 | typename _IteratorCategory>
|
---|
45 | class _IteratorPair : public std::pair<_Iterator1, _Iterator2>
|
---|
46 | {
|
---|
47 | private:
|
---|
48 | typedef std::pair<_Iterator1, _Iterator2> _Base;
|
---|
49 |
|
---|
50 | public:
|
---|
51 | typedef _IteratorCategory iterator_category;
|
---|
52 | typedef void value_type;
|
---|
53 |
|
---|
54 | typedef std::iterator_traits<_Iterator1> _TraitsType;
|
---|
55 | typedef typename _TraitsType::difference_type difference_type;
|
---|
56 | typedef _IteratorPair* pointer;
|
---|
57 | typedef _IteratorPair& reference;
|
---|
58 |
|
---|
59 | _IteratorPair() { }
|
---|
60 |
|
---|
61 | _IteratorPair(const _Iterator1& __first, const _Iterator2& __second)
|
---|
62 | : _Base(__first, __second) { }
|
---|
63 |
|
---|
64 | // Pre-increment operator.
|
---|
65 | _IteratorPair&
|
---|
66 | operator++()
|
---|
67 | {
|
---|
68 | ++_Base::first;
|
---|
69 | ++_Base::second;
|
---|
70 | return *this;
|
---|
71 | }
|
---|
72 |
|
---|
73 | // Post-increment operator.
|
---|
74 | const _IteratorPair
|
---|
75 | operator++(int)
|
---|
76 | { return _IteratorPair(_Base::first++, _Base::second++); }
|
---|
77 |
|
---|
78 | // Pre-decrement operator.
|
---|
79 | _IteratorPair&
|
---|
80 | operator--()
|
---|
81 | {
|
---|
82 | --_Base::first;
|
---|
83 | --_Base::second;
|
---|
84 | return *this;
|
---|
85 | }
|
---|
86 |
|
---|
87 | // Post-decrement operator.
|
---|
88 | const _IteratorPair
|
---|
89 | operator--(int)
|
---|
90 | { return _IteratorPair(_Base::first--, _Base::second--); }
|
---|
91 |
|
---|
92 | // Type conversion.
|
---|
93 | operator _Iterator2() const
|
---|
94 | { return _Base::second; }
|
---|
95 |
|
---|
96 | _IteratorPair&
|
---|
97 | operator=(const _IteratorPair& __other)
|
---|
98 | {
|
---|
99 | _Base::first = __other.first;
|
---|
100 | _Base::second = __other.second;
|
---|
101 | return *this;
|
---|
102 | }
|
---|
103 |
|
---|
104 | _IteratorPair
|
---|
105 | operator+(difference_type __delta) const
|
---|
106 | { return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
|
---|
107 | }
|
---|
108 |
|
---|
109 | difference_type
|
---|
110 | operator-(const _IteratorPair& __other) const
|
---|
111 | { return _Base::first - __other.first; }
|
---|
112 | };
|
---|
113 |
|
---|
114 |
|
---|
115 | /** @brief A triple of iterators. The usual iterator operations are
|
---|
116 | applied to all three child iterators.
|
---|
117 | */
|
---|
118 | template<typename _Iterator1, typename _Iterator2, typename _Iterator3,
|
---|
119 | typename _IteratorCategory>
|
---|
120 | class _IteratorTriple
|
---|
121 | {
|
---|
122 | public:
|
---|
123 | typedef _IteratorCategory iterator_category;
|
---|
124 | typedef void value_type;
|
---|
125 | typedef typename std::iterator_traits<_Iterator1>::difference_type
|
---|
126 | difference_type;
|
---|
127 | typedef _IteratorTriple* pointer;
|
---|
128 | typedef _IteratorTriple& reference;
|
---|
129 |
|
---|
130 | _Iterator1 _M_first;
|
---|
131 | _Iterator2 _M_second;
|
---|
132 | _Iterator3 _M_third;
|
---|
133 |
|
---|
134 | _IteratorTriple() { }
|
---|
135 |
|
---|
136 | _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second,
|
---|
137 | const _Iterator3& __third)
|
---|
138 | {
|
---|
139 | _M_first = __first;
|
---|
140 | _M_second = __second;
|
---|
141 | _M_third = __third;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Pre-increment operator.
|
---|
145 | _IteratorTriple&
|
---|
146 | operator++()
|
---|
147 | {
|
---|
148 | ++_M_first;
|
---|
149 | ++_M_second;
|
---|
150 | ++_M_third;
|
---|
151 | return *this;
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Post-increment operator.
|
---|
155 | const _IteratorTriple
|
---|
156 | operator++(int)
|
---|
157 | { return _IteratorTriple(_M_first++, _M_second++, _M_third++); }
|
---|
158 |
|
---|
159 | // Pre-decrement operator.
|
---|
160 | _IteratorTriple&
|
---|
161 | operator--()
|
---|
162 | {
|
---|
163 | --_M_first;
|
---|
164 | --_M_second;
|
---|
165 | --_M_third;
|
---|
166 | return *this;
|
---|
167 | }
|
---|
168 |
|
---|
169 | // Post-decrement operator.
|
---|
170 | const _IteratorTriple
|
---|
171 | operator--(int)
|
---|
172 | { return _IteratorTriple(_M_first--, _M_second--, _M_third--); }
|
---|
173 |
|
---|
174 | // Type conversion.
|
---|
175 | operator _Iterator3() const
|
---|
176 | { return _M_third; }
|
---|
177 |
|
---|
178 | _IteratorTriple&
|
---|
179 | operator=(const _IteratorTriple& __other)
|
---|
180 | {
|
---|
181 | _M_first = __other._M_first;
|
---|
182 | _M_second = __other._M_second;
|
---|
183 | _M_third = __other._M_third;
|
---|
184 | return *this;
|
---|
185 | }
|
---|
186 |
|
---|
187 | _IteratorTriple
|
---|
188 | operator+(difference_type __delta) const
|
---|
189 | { return _IteratorTriple(_M_first + __delta, _M_second + __delta,
|
---|
190 | _M_third + __delta); }
|
---|
191 |
|
---|
192 | difference_type
|
---|
193 | operator-(const _IteratorTriple& __other) const
|
---|
194 | { return _M_first - __other._M_first; }
|
---|
195 | };
|
---|
196 | }
|
---|
197 |
|
---|
198 | #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */
|
---|