3 // Copyright (C) 2007, 2008 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 2, 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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 /** @file parallel/iterator.h
32 * @brief Helper iterator classes for the std::transform() functions.
33 * This file is a GNU parallel extension to the Standard C++ Library.
36 // Written by Johannes Singler.
38 #ifndef _GLIBCXX_PARALLEL_ITERATOR_H
39 #define _GLIBCXX_PARALLEL_ITERATOR_H 1
41 #include <parallel/basic_iterator.h>
42 #include <bits/stl_pair.h>
44 namespace __gnu_parallel
46 /** @brief A pair of iterators. The usual iterator operations are
47 * applied to both child iterators.
49 template<typename Iterator1, typename Iterator2, typename IteratorCategory>
50 class iterator_pair : public std::pair<Iterator1, Iterator2>
53 typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type;
54 typedef std::pair<Iterator1, Iterator2> base_type;
57 typedef IteratorCategory iterator_category;
58 typedef void value_type;
60 typedef std::iterator_traits<Iterator1> traits_type;
61 typedef typename traits_type::difference_type difference_type;
62 typedef type* pointer;
63 typedef type& reference;
67 iterator_pair(const Iterator1& first, const Iterator2& second)
68 : base_type(first, second) { }
70 // Pre-increment operator.
79 // Post-increment operator.
82 { return type(base_type::first++, base_type::second++); }
84 // Pre-decrement operator.
93 // Post-decrement operator.
96 { return type(base_type::first--, base_type::second--); }
99 operator Iterator2() const
100 { return base_type::second; }
103 operator=(const type& other)
105 base_type::first = other.first;
106 base_type::second = other.second;
111 operator+(difference_type delta) const
112 { return type(base_type::first + delta, base_type::second + delta); }
115 operator-(const type& other) const
116 { return base_type::first - other.first; }
120 /** @brief A triple of iterators. The usual iterator operations are
121 applied to all three child iterators.
123 template<typename Iterator1, typename Iterator2, typename Iterator3,
124 typename IteratorCategory>
125 class iterator_triple
128 typedef iterator_triple<Iterator1, Iterator2, Iterator3,
129 IteratorCategory> type;
132 typedef IteratorCategory iterator_category;
133 typedef void value_type;
134 typedef typename std::iterator_traits<Iterator1>::difference_type
136 typedef type* pointer;
137 typedef type& reference;
143 iterator_triple() { }
145 iterator_triple(const Iterator1& _first, const Iterator2& _second,
146 const Iterator3& _third)
153 // Pre-increment operator.
163 // Post-increment operator.
166 { return type(first++, second++, third++); }
168 // Pre-decrement operator.
178 // Post-decrement operator.
181 { return type(first--, second--, third--); }
184 operator Iterator3() const
188 operator=(const type& other)
191 second = other.second;
197 operator+(difference_type delta) const
198 { return type(first + delta, second + delta, third + delta); }
201 operator-(const type& other) const
202 { return first - other.first; }
206 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */