3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
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
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>
48 typedef std::pair<_Iterator1, _Iterator2> _Base;
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;
61 _IteratorPair(const _Iterator1& __first, const _Iterator2& __second)
62 : _Base(__first, __second) { }
64 // Pre-increment operator.
73 // Post-increment operator.
76 { return _IteratorPair(_Base::first++, _Base::second++); }
78 // Pre-decrement operator.
87 // Post-decrement operator.
90 { return _IteratorPair(_Base::first--, _Base::second--); }
93 operator _Iterator2() const
94 { return _Base::second; }
97 operator=(const _IteratorPair& __other)
99 _Base::first = __other.first;
100 _Base::second = __other.second;
105 operator+(difference_type __delta) const
106 { return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
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
123 typedef _IteratorCategory iterator_category;
124 typedef void value_type;
125 typedef typename std::iterator_traits<_Iterator1>::difference_type
127 typedef _IteratorTriple* pointer;
128 typedef _IteratorTriple& reference;
131 _Iterator2 _M_second;
134 _IteratorTriple() { }
136 _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second,
137 const _Iterator3& __third)
140 _M_second = __second;
144 // Pre-increment operator.
154 // Post-increment operator.
155 const _IteratorTriple
157 { return _IteratorTriple(_M_first++, _M_second++, _M_third++); }
159 // Pre-decrement operator.
169 // Post-decrement operator.
170 const _IteratorTriple
172 { return _IteratorTriple(_M_first--, _M_second--, _M_third--); }
175 operator _Iterator3() const
179 operator=(const _IteratorTriple& __other)
181 _M_first = __other._M_first;
182 _M_second = __other._M_second;
183 _M_third = __other._M_third;
188 operator+(difference_type __delta) const
189 { return _IteratorTriple(_M_first + __delta, _M_second + __delta,
190 _M_third + __delta); }
193 operator-(const _IteratorTriple& __other) const
194 { return _M_first - __other._M_first; }
198 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */