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, typename IteratorCategory>
44 class iterator_pair : public std::pair<Iterator1, Iterator2>
47 typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type;
48 typedef std::pair<Iterator1, Iterator2> base_type;
51 typedef IteratorCategory iterator_category;
52 typedef void value_type;
54 typedef std::iterator_traits<Iterator1> traits_type;
55 typedef typename traits_type::difference_type difference_type;
56 typedef type* pointer;
57 typedef type& reference;
61 iterator_pair(const Iterator1& first, const Iterator2& second)
62 : base_type(first, second) { }
64 // Pre-increment operator.
73 // Post-increment operator.
76 { return type(base_type::first++, base_type::second++); }
78 // Pre-decrement operator.
87 // Post-decrement operator.
90 { return type(base_type::first--, base_type::second--); }
93 operator Iterator2() const
94 { return base_type::second; }
97 operator=(const type& other)
99 base_type::first = other.first;
100 base_type::second = other.second;
105 operator+(difference_type delta) const
106 { return type(base_type::first + delta, base_type::second + delta); }
109 operator-(const type& other) const
110 { return base_type::first - other.first; }
114 /** @brief A triple of iterators. The usual iterator operations are
115 applied to all three child iterators.
117 template<typename Iterator1, typename Iterator2, typename Iterator3,
118 typename IteratorCategory>
119 class iterator_triple
122 typedef iterator_triple<Iterator1, Iterator2, Iterator3,
123 IteratorCategory> type;
126 typedef IteratorCategory iterator_category;
127 typedef void value_type;
128 typedef typename std::iterator_traits<Iterator1>::difference_type
130 typedef type* pointer;
131 typedef type& reference;
137 iterator_triple() { }
139 iterator_triple(const Iterator1& _first, const Iterator2& _second,
140 const Iterator3& _third)
147 // Pre-increment operator.
157 // Post-increment operator.
160 { return type(first++, second++, third++); }
162 // Pre-decrement operator.
172 // Post-decrement operator.
175 { return type(first--, second--, third--); }
178 operator Iterator3() const
182 operator=(const type& other)
185 second = other.second;
191 operator+(difference_type delta) const
192 { return type(first + delta, second + delta, third + delta); }
195 operator-(const type& other) const
196 { return first - other.first; }
200 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */