Import GCC-8 to a new vendor branch
[dragonfly.git] / contrib / gcc-8.0 / libstdc++-v3 / include / parallel / iterator.h
blob05f83d8496ac48519bf7d9344d53133e2eda4f3a
1 // -*- C++ -*-
3 // Copyright (C) 2007-2018 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.
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.
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.
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/>.
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.
30 // Written by Johannes Singler.
32 #ifndef _GLIBCXX_PARALLEL_ITERATOR_H
33 #define _GLIBCXX_PARALLEL_ITERATOR_H 1
35 #include <parallel/basic_iterator.h>
36 #include <bits/stl_pair.h>
38 namespace __gnu_parallel
40 /** @brief A pair of iterators. The usual iterator operations are
41 * applied to both child iterators.
43 template<typename _Iterator1, typename _Iterator2,
44 typename _IteratorCategory>
45 class _IteratorPair : public std::pair<_Iterator1, _Iterator2>
47 private:
48 typedef std::pair<_Iterator1, _Iterator2> _Base;
50 public:
51 typedef _IteratorCategory iterator_category;
52 typedef void value_type;
54 typedef std::iterator_traits<_Iterator1> _TraitsType;
55 typedef typename _TraitsType::difference_type difference_type;
56 typedef _IteratorPair* pointer;
57 typedef _IteratorPair& reference;
59 _IteratorPair() { }
61 _IteratorPair(const _Iterator1& __first, const _Iterator2& __second)
62 : _Base(__first, __second) { }
64 // Pre-increment operator.
65 _IteratorPair&
66 operator++()
68 ++_Base::first;
69 ++_Base::second;
70 return *this;
73 // Post-increment operator.
74 const _IteratorPair
75 operator++(int)
76 { return _IteratorPair(_Base::first++, _Base::second++); }
78 // Pre-decrement operator.
79 _IteratorPair&
80 operator--()
82 --_Base::first;
83 --_Base::second;
84 return *this;
87 // Post-decrement operator.
88 const _IteratorPair
89 operator--(int)
90 { return _IteratorPair(_Base::first--, _Base::second--); }
92 // Type conversion.
93 operator _Iterator2() const
94 { return _Base::second; }
96 _IteratorPair&
97 operator=(const _IteratorPair& __other)
99 _Base::first = __other.first;
100 _Base::second = __other.second;
101 return *this;
104 _IteratorPair
105 operator+(difference_type __delta) const
106 { return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
109 difference_type
110 operator-(const _IteratorPair& __other) const
111 { return _Base::first - __other.first; }
115 /** @brief A triple of iterators. The usual iterator operations are
116 applied to all three child iterators.
118 template<typename _Iterator1, typename _Iterator2, typename _Iterator3,
119 typename _IteratorCategory>
120 class _IteratorTriple
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;
130 _Iterator1 _M_first;
131 _Iterator2 _M_second;
132 _Iterator3 _M_third;
134 _IteratorTriple() { }
136 _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second,
137 const _Iterator3& __third)
139 _M_first = __first;
140 _M_second = __second;
141 _M_third = __third;
144 // Pre-increment operator.
145 _IteratorTriple&
146 operator++()
148 ++_M_first;
149 ++_M_second;
150 ++_M_third;
151 return *this;
154 // Post-increment operator.
155 const _IteratorTriple
156 operator++(int)
157 { return _IteratorTriple(_M_first++, _M_second++, _M_third++); }
159 // Pre-decrement operator.
160 _IteratorTriple&
161 operator--()
163 --_M_first;
164 --_M_second;
165 --_M_third;
166 return *this;
169 // Post-decrement operator.
170 const _IteratorTriple
171 operator--(int)
172 { return _IteratorTriple(_M_first--, _M_second--, _M_third--); }
174 // Type conversion.
175 operator _Iterator3() const
176 { return _M_third; }
178 _IteratorTriple&
179 operator=(const _IteratorTriple& __other)
181 _M_first = __other._M_first;
182 _M_second = __other._M_second;
183 _M_third = __other._M_third;
184 return *this;
187 _IteratorTriple
188 operator+(difference_type __delta) const
189 { return _IteratorTriple(_M_first + __delta, _M_second + __delta,
190 _M_third + __delta); }
192 difference_type
193 operator-(const _IteratorTriple& __other) const
194 { return _M_first - __other._M_first; }
198 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */