]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/parallel/iterator.h
Inital import
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / parallel / iterator.h
1 // -*- C++ -*-
2
3 // Copyright (C) 2007, 2008 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 2, or (at your option) any later
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
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.
20
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
29 // Public License.
30
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.
34  */
35
36 // Written by Johannes Singler.
37
38 #ifndef _GLIBCXX_PARALLEL_ITERATOR_H
39 #define _GLIBCXX_PARALLEL_ITERATOR_H 1
40
41 #include <parallel/basic_iterator.h>
42 #include <bits/stl_pair.h>
43
44 namespace __gnu_parallel
45 {
46   /** @brief A pair of iterators. The usual iterator operations are
47    *  applied to both child iterators.
48    */
49   template<typename Iterator1, typename Iterator2, typename IteratorCategory>
50     class iterator_pair : public std::pair<Iterator1, Iterator2>
51     {
52     private:
53       typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type;
54       typedef std::pair<Iterator1, Iterator2> base_type;
55
56     public:
57       typedef IteratorCategory iterator_category;
58       typedef void value_type;
59
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;
64
65       iterator_pair() { }
66
67       iterator_pair(const Iterator1& first, const Iterator2& second) 
68       : base_type(first, second) { }
69
70       // Pre-increment operator.
71       type&
72       operator++()
73       {
74         ++base_type::first;
75         ++base_type::second;
76         return *this;
77       }
78
79       // Post-increment operator.
80       const type
81       operator++(int)
82       { return type(base_type::first++, base_type::second++); }
83
84       // Pre-decrement operator.
85       type&
86       operator--()
87       {
88         --base_type::first;
89         --base_type::second;
90         return *this;
91       }
92
93       // Post-decrement operator.
94       const type
95       operator--(int)
96       { return type(base_type::first--, base_type::second--); }
97
98       // Type conversion.
99       operator Iterator2() const
100       { return base_type::second; }
101
102       type&
103       operator=(const type& other)
104       {
105         base_type::first = other.first;
106         base_type::second = other.second;
107         return *this;
108       }
109
110       type
111       operator+(difference_type delta) const
112       { return type(base_type::first + delta, base_type::second + delta); }
113
114       difference_type
115       operator-(const type& other) const
116       { return base_type::first - other.first; }
117   };
118
119
120   /** @brief A triple of iterators. The usual iterator operations are
121       applied to all three child iterators.
122    */
123   template<typename Iterator1, typename Iterator2, typename Iterator3,
124            typename IteratorCategory>
125     class iterator_triple
126     {
127     private:
128       typedef iterator_triple<Iterator1, Iterator2, Iterator3,
129                               IteratorCategory> type;
130
131     public:
132       typedef IteratorCategory iterator_category;
133       typedef void value_type;
134       typedef typename Iterator1::difference_type difference_type;
135       typedef type* pointer;
136       typedef type& reference;
137
138       Iterator1 first;
139       Iterator2 second;
140       Iterator3 third;
141
142       iterator_triple() { }
143
144       iterator_triple(const Iterator1& _first, const Iterator2& _second,
145                       const Iterator3& _third)
146       {
147         first = _first;
148         second = _second;
149         third = _third;
150       }
151
152       // Pre-increment operator.
153       type&
154       operator++()
155       {
156         ++first;
157         ++second;
158         ++third;
159         return *this;
160       }
161
162       // Post-increment operator.
163       const type
164       operator++(int)
165       { return type(first++, second++, third++); }
166
167       // Pre-decrement operator.
168       type&
169       operator--()
170       {
171         --first;
172         --second;
173         --third;
174         return *this;
175       }
176
177       // Post-decrement operator.
178       const type
179       operator--(int)
180       { return type(first--, second--, third--); }
181
182       // Type conversion.
183       operator Iterator3() const
184       { return third; }
185
186       type&
187       operator=(const type& other)
188       {
189         first = other.first;
190         second = other.second;
191         third = other.third;
192         return *this;
193       }
194
195       type
196       operator+(difference_type delta) const
197       { return type(first + delta, second + delta, third + delta); }
198
199       difference_type
200       operator-(const type& other) const
201       { return first - other.first; }
202   };
203 }
204
205 #endif