]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/parallel/iterator.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / parallel / iterator.h
CommitLineData
c2ba9709
JS
1// -*- C++ -*-
2
99dee823 3// Copyright (C) 2007-2021 Free Software Foundation, Inc.
c2ba9709
JS
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
748086b7 8// Foundation; either version 3, or (at your option) any later
c2ba9709
JS
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
748086b7
JJ
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.
c2ba9709 19
748086b7
JJ
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/>.
c2ba9709
JS
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
38namespace __gnu_parallel
39{
40 /** @brief A pair of iterators. The usual iterator operations are
41 * applied to both child iterators.
42 */
15ac3c72
JS
43 template<typename _Iterator1, typename _Iterator2,
44 typename _IteratorCategory>
1acba85b 45 class _IteratorPair : public std::pair<_Iterator1, _Iterator2>
c2ba9709 46 {
531898c3 47 private:
1acba85b 48 typedef std::pair<_Iterator1, _Iterator2> _Base;
531898c3
PC
49
50 public:
1acba85b 51 typedef _IteratorCategory iterator_category;
531898c3
PC
52 typedef void value_type;
53
1acba85b
JS
54 typedef std::iterator_traits<_Iterator1> _TraitsType;
55 typedef typename _TraitsType::difference_type difference_type;
11b9c936
JS
56 typedef _IteratorPair* pointer;
57 typedef _IteratorPair& reference;
531898c3 58
1acba85b 59 _IteratorPair() { }
531898c3 60
15ac3c72 61 _IteratorPair(const _Iterator1& __first, const _Iterator2& __second)
1acba85b 62 : _Base(__first, __second) { }
531898c3
PC
63
64 // Pre-increment operator.
11b9c936 65 _IteratorPair&
531898c3
PC
66 operator++()
67 {
15ac3c72
JS
68 ++_Base::first;
69 ++_Base::second;
70 return *this;
531898c3
PC
71 }
72
73 // Post-increment operator.
11b9c936 74 const _IteratorPair
531898c3 75 operator++(int)
11b9c936 76 { return _IteratorPair(_Base::first++, _Base::second++); }
531898c3
PC
77
78 // Pre-decrement operator.
11b9c936 79 _IteratorPair&
531898c3
PC
80 operator--()
81 {
15ac3c72
JS
82 --_Base::first;
83 --_Base::second;
84 return *this;
531898c3
PC
85 }
86
87 // Post-decrement operator.
11b9c936 88 const _IteratorPair
531898c3 89 operator--(int)
11b9c936 90 { return _IteratorPair(_Base::first--, _Base::second--); }
531898c3
PC
91
92 // Type conversion.
1acba85b
JS
93 operator _Iterator2() const
94 { return _Base::second; }
531898c3 95
11b9c936
JS
96 _IteratorPair&
97 operator=(const _IteratorPair& __other)
531898c3 98 {
15ac3c72
JS
99 _Base::first = __other.first;
100 _Base::second = __other.second;
101 return *this;
531898c3
PC
102 }
103
11b9c936 104 _IteratorPair
1acba85b 105 operator+(difference_type __delta) const
15ac3c72
JS
106 { return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
107 }
531898c3
PC
108
109 difference_type
11b9c936 110 operator-(const _IteratorPair& __other) const
1acba85b 111 { return _Base::first - __other.first; }
c2ba9709
JS
112 };
113
114
115 /** @brief A triple of iterators. The usual iterator operations are
116 applied to all three child iterators.
117 */
1acba85b 118 template<typename _Iterator1, typename _Iterator2, typename _Iterator3,
15ac3c72 119 typename _IteratorCategory>
1acba85b 120 class _IteratorTriple
c2ba9709 121 {
531898c3 122 public:
1acba85b 123 typedef _IteratorCategory iterator_category;
531898c3 124 typedef void value_type;
1acba85b 125 typedef typename std::iterator_traits<_Iterator1>::difference_type
22ec53ec 126 difference_type;
11b9c936
JS
127 typedef _IteratorTriple* pointer;
128 typedef _IteratorTriple& reference;
531898c3 129
54384f7f
JS
130 _Iterator1 _M_first;
131 _Iterator2 _M_second;
132 _Iterator3 _M_third;
531898c3 133
1acba85b 134 _IteratorTriple() { }
531898c3 135
54384f7f 136 _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second,
15ac3c72 137 const _Iterator3& __third)
531898c3 138 {
15ac3c72
JS
139 _M_first = __first;
140 _M_second = __second;
141 _M_third = __third;
531898c3
PC
142 }
143
144 // Pre-increment operator.
11b9c936 145 _IteratorTriple&
531898c3
PC
146 operator++()
147 {
15ac3c72
JS
148 ++_M_first;
149 ++_M_second;
150 ++_M_third;
151 return *this;
531898c3
PC
152 }
153
154 // Post-increment operator.
11b9c936 155 const _IteratorTriple
531898c3 156 operator++(int)
54384f7f 157 { return _IteratorTriple(_M_first++, _M_second++, _M_third++); }
531898c3
PC
158
159 // Pre-decrement operator.
11b9c936 160 _IteratorTriple&
531898c3
PC
161 operator--()
162 {
15ac3c72
JS
163 --_M_first;
164 --_M_second;
165 --_M_third;
166 return *this;
531898c3
PC
167 }
168
169 // Post-decrement operator.
11b9c936 170 const _IteratorTriple
531898c3 171 operator--(int)
54384f7f 172 { return _IteratorTriple(_M_first--, _M_second--, _M_third--); }
531898c3
PC
173
174 // Type conversion.
1acba85b 175 operator _Iterator3() const
54384f7f 176 { return _M_third; }
531898c3 177
11b9c936
JS
178 _IteratorTriple&
179 operator=(const _IteratorTriple& __other)
531898c3 180 {
15ac3c72
JS
181 _M_first = __other._M_first;
182 _M_second = __other._M_second;
183 _M_third = __other._M_third;
184 return *this;
531898c3
PC
185 }
186
11b9c936 187 _IteratorTriple
1acba85b 188 operator+(difference_type __delta) const
15ac3c72
JS
189 { return _IteratorTriple(_M_first + __delta, _M_second + __delta,
190 _M_third + __delta); }
531898c3
PC
191
192 difference_type
11b9c936 193 operator-(const _IteratorTriple& __other) const
54384f7f 194 { return _M_first - __other._M_first; }
c2ba9709
JS
195 };
196}
197
cbcd1e45 198#endif /* _GLIBCXX_PARALLEL_ITERATOR_H */