OSDN Git Service

95ef844350fbeafd7c7aee0e42f87f49c2da6c0f
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / 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 std::iterator_traits<Iterator1>::difference_type
135                                                             difference_type;
136       typedef type* pointer;
137       typedef type& reference;
138
139       Iterator1 first;
140       Iterator2 second;
141       Iterator3 third;
142
143       iterator_triple() { }
144
145       iterator_triple(const Iterator1& _first, const Iterator2& _second,
146                       const Iterator3& _third)
147       {
148         first = _first;
149         second = _second;
150         third = _third;
151       }
152
153       // Pre-increment operator.
154       type&
155       operator++()
156       {
157         ++first;
158         ++second;
159         ++third;
160         return *this;
161       }
162
163       // Post-increment operator.
164       const type
165       operator++(int)
166       { return type(first++, second++, third++); }
167
168       // Pre-decrement operator.
169       type&
170       operator--()
171       {
172         --first;
173         --second;
174         --third;
175         return *this;
176       }
177
178       // Post-decrement operator.
179       const type
180       operator--(int)
181       { return type(first--, second--, third--); }
182
183       // Type conversion.
184       operator Iterator3() const
185       { return third; }
186
187       type&
188       operator=(const type& other)
189       {
190         first = other.first;
191         second = other.second;
192         third = other.third;
193         return *this;
194       }
195
196       type
197       operator+(difference_type delta) const
198       { return type(first + delta, second + delta, third + delta); }
199
200       difference_type
201       operator-(const type& other) const
202       { return first - other.first; }
203   };
204 }
205
206 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */