xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/parallel/iterator.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // -*- C++ -*-
2*e4b17023SJohn Marino 
3*e4b17023SJohn Marino // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
4*e4b17023SJohn Marino //
5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the terms
7*e4b17023SJohn Marino // of the GNU General Public License as published by the Free Software
8*e4b17023SJohn Marino // Foundation; either version 3, or (at your option) any later
9*e4b17023SJohn Marino // version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, but
12*e4b17023SJohn Marino // WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*e4b17023SJohn Marino // General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino /** @file parallel/iterator.h
26*e4b17023SJohn Marino  * @brief Helper iterator classes for the std::transform() functions.
27*e4b17023SJohn Marino  *  This file is a GNU parallel extension to the Standard C++ Library.
28*e4b17023SJohn Marino  */
29*e4b17023SJohn Marino 
30*e4b17023SJohn Marino // Written by Johannes Singler.
31*e4b17023SJohn Marino 
32*e4b17023SJohn Marino #ifndef _GLIBCXX_PARALLEL_ITERATOR_H
33*e4b17023SJohn Marino #define _GLIBCXX_PARALLEL_ITERATOR_H 1
34*e4b17023SJohn Marino 
35*e4b17023SJohn Marino #include <parallel/basic_iterator.h>
36*e4b17023SJohn Marino #include <bits/stl_pair.h>
37*e4b17023SJohn Marino 
38*e4b17023SJohn Marino namespace __gnu_parallel
39*e4b17023SJohn Marino {
40*e4b17023SJohn Marino   /** @brief A pair of iterators. The usual iterator operations are
41*e4b17023SJohn Marino    *  applied to both child iterators.
42*e4b17023SJohn Marino    */
43*e4b17023SJohn Marino   template<typename _Iterator1, typename _Iterator2,
44*e4b17023SJohn Marino            typename _IteratorCategory>
45*e4b17023SJohn Marino     class _IteratorPair : public std::pair<_Iterator1, _Iterator2>
46*e4b17023SJohn Marino     {
47*e4b17023SJohn Marino     private:
48*e4b17023SJohn Marino       typedef std::pair<_Iterator1, _Iterator2> _Base;
49*e4b17023SJohn Marino 
50*e4b17023SJohn Marino     public:
51*e4b17023SJohn Marino       typedef _IteratorCategory iterator_category;
52*e4b17023SJohn Marino       typedef void value_type;
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino       typedef std::iterator_traits<_Iterator1> _TraitsType;
55*e4b17023SJohn Marino       typedef typename _TraitsType::difference_type difference_type;
56*e4b17023SJohn Marino       typedef _IteratorPair* pointer;
57*e4b17023SJohn Marino       typedef _IteratorPair& reference;
58*e4b17023SJohn Marino 
_IteratorPair()59*e4b17023SJohn Marino       _IteratorPair() { }
60*e4b17023SJohn Marino 
_IteratorPair(const _Iterator1 & __first,const _Iterator2 & __second)61*e4b17023SJohn Marino       _IteratorPair(const _Iterator1& __first, const _Iterator2& __second)
62*e4b17023SJohn Marino       : _Base(__first, __second) { }
63*e4b17023SJohn Marino 
64*e4b17023SJohn Marino       // Pre-increment operator.
65*e4b17023SJohn Marino       _IteratorPair&
66*e4b17023SJohn Marino       operator++()
67*e4b17023SJohn Marino       {
68*e4b17023SJohn Marino         ++_Base::first;
69*e4b17023SJohn Marino         ++_Base::second;
70*e4b17023SJohn Marino         return *this;
71*e4b17023SJohn Marino       }
72*e4b17023SJohn Marino 
73*e4b17023SJohn Marino       // Post-increment operator.
74*e4b17023SJohn Marino       const _IteratorPair
75*e4b17023SJohn Marino       operator++(int)
76*e4b17023SJohn Marino       { return _IteratorPair(_Base::first++, _Base::second++); }
77*e4b17023SJohn Marino 
78*e4b17023SJohn Marino       // Pre-decrement operator.
79*e4b17023SJohn Marino       _IteratorPair&
80*e4b17023SJohn Marino       operator--()
81*e4b17023SJohn Marino       {
82*e4b17023SJohn Marino         --_Base::first;
83*e4b17023SJohn Marino         --_Base::second;
84*e4b17023SJohn Marino         return *this;
85*e4b17023SJohn Marino       }
86*e4b17023SJohn Marino 
87*e4b17023SJohn Marino       // Post-decrement operator.
88*e4b17023SJohn Marino       const _IteratorPair
89*e4b17023SJohn Marino       operator--(int)
90*e4b17023SJohn Marino       { return _IteratorPair(_Base::first--, _Base::second--); }
91*e4b17023SJohn Marino 
92*e4b17023SJohn Marino       // Type conversion.
_Iterator2()93*e4b17023SJohn Marino       operator _Iterator2() const
94*e4b17023SJohn Marino       { return _Base::second; }
95*e4b17023SJohn Marino 
96*e4b17023SJohn Marino       _IteratorPair&
97*e4b17023SJohn Marino       operator=(const _IteratorPair& __other)
98*e4b17023SJohn Marino       {
99*e4b17023SJohn Marino         _Base::first = __other.first;
100*e4b17023SJohn Marino         _Base::second = __other.second;
101*e4b17023SJohn Marino         return *this;
102*e4b17023SJohn Marino       }
103*e4b17023SJohn Marino 
104*e4b17023SJohn Marino       _IteratorPair
105*e4b17023SJohn Marino       operator+(difference_type __delta) const
106*e4b17023SJohn Marino       { return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
107*e4b17023SJohn Marino         }
108*e4b17023SJohn Marino 
109*e4b17023SJohn Marino       difference_type
110*e4b17023SJohn Marino       operator-(const _IteratorPair& __other) const
111*e4b17023SJohn Marino       { return _Base::first - __other.first; }
112*e4b17023SJohn Marino   };
113*e4b17023SJohn Marino 
114*e4b17023SJohn Marino 
115*e4b17023SJohn Marino   /** @brief A triple of iterators. The usual iterator operations are
116*e4b17023SJohn Marino       applied to all three child iterators.
117*e4b17023SJohn Marino    */
118*e4b17023SJohn Marino   template<typename _Iterator1, typename _Iterator2, typename _Iterator3,
119*e4b17023SJohn Marino            typename _IteratorCategory>
120*e4b17023SJohn Marino     class _IteratorTriple
121*e4b17023SJohn Marino     {
122*e4b17023SJohn Marino     public:
123*e4b17023SJohn Marino       typedef _IteratorCategory iterator_category;
124*e4b17023SJohn Marino       typedef void value_type;
125*e4b17023SJohn Marino       typedef typename std::iterator_traits<_Iterator1>::difference_type
126*e4b17023SJohn Marino                                                             difference_type;
127*e4b17023SJohn Marino       typedef _IteratorTriple* pointer;
128*e4b17023SJohn Marino       typedef _IteratorTriple& reference;
129*e4b17023SJohn Marino 
130*e4b17023SJohn Marino       _Iterator1 _M_first;
131*e4b17023SJohn Marino       _Iterator2 _M_second;
132*e4b17023SJohn Marino       _Iterator3 _M_third;
133*e4b17023SJohn Marino 
_IteratorTriple()134*e4b17023SJohn Marino       _IteratorTriple() { }
135*e4b17023SJohn Marino 
_IteratorTriple(const _Iterator1 & __first,const _Iterator2 & __second,const _Iterator3 & __third)136*e4b17023SJohn Marino       _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second,
137*e4b17023SJohn Marino                       const _Iterator3& __third)
138*e4b17023SJohn Marino       {
139*e4b17023SJohn Marino         _M_first = __first;
140*e4b17023SJohn Marino         _M_second = __second;
141*e4b17023SJohn Marino         _M_third = __third;
142*e4b17023SJohn Marino       }
143*e4b17023SJohn Marino 
144*e4b17023SJohn Marino       // Pre-increment operator.
145*e4b17023SJohn Marino       _IteratorTriple&
146*e4b17023SJohn Marino       operator++()
147*e4b17023SJohn Marino       {
148*e4b17023SJohn Marino         ++_M_first;
149*e4b17023SJohn Marino         ++_M_second;
150*e4b17023SJohn Marino         ++_M_third;
151*e4b17023SJohn Marino         return *this;
152*e4b17023SJohn Marino       }
153*e4b17023SJohn Marino 
154*e4b17023SJohn Marino       // Post-increment operator.
155*e4b17023SJohn Marino       const _IteratorTriple
156*e4b17023SJohn Marino       operator++(int)
157*e4b17023SJohn Marino       { return _IteratorTriple(_M_first++, _M_second++, _M_third++); }
158*e4b17023SJohn Marino 
159*e4b17023SJohn Marino       // Pre-decrement operator.
160*e4b17023SJohn Marino       _IteratorTriple&
161*e4b17023SJohn Marino       operator--()
162*e4b17023SJohn Marino       {
163*e4b17023SJohn Marino         --_M_first;
164*e4b17023SJohn Marino         --_M_second;
165*e4b17023SJohn Marino         --_M_third;
166*e4b17023SJohn Marino         return *this;
167*e4b17023SJohn Marino       }
168*e4b17023SJohn Marino 
169*e4b17023SJohn Marino       // Post-decrement operator.
170*e4b17023SJohn Marino       const _IteratorTriple
171*e4b17023SJohn Marino       operator--(int)
172*e4b17023SJohn Marino       { return _IteratorTriple(_M_first--, _M_second--, _M_third--); }
173*e4b17023SJohn Marino 
174*e4b17023SJohn Marino       // Type conversion.
_Iterator3()175*e4b17023SJohn Marino       operator _Iterator3() const
176*e4b17023SJohn Marino       { return _M_third; }
177*e4b17023SJohn Marino 
178*e4b17023SJohn Marino       _IteratorTriple&
179*e4b17023SJohn Marino       operator=(const _IteratorTriple& __other)
180*e4b17023SJohn Marino       {
181*e4b17023SJohn Marino         _M_first = __other._M_first;
182*e4b17023SJohn Marino         _M_second = __other._M_second;
183*e4b17023SJohn Marino         _M_third = __other._M_third;
184*e4b17023SJohn Marino         return *this;
185*e4b17023SJohn Marino       }
186*e4b17023SJohn Marino 
187*e4b17023SJohn Marino       _IteratorTriple
188*e4b17023SJohn Marino       operator+(difference_type __delta) const
189*e4b17023SJohn Marino       { return _IteratorTriple(_M_first + __delta, _M_second + __delta,
190*e4b17023SJohn Marino                                _M_third + __delta); }
191*e4b17023SJohn Marino 
192*e4b17023SJohn Marino       difference_type
193*e4b17023SJohn Marino       operator-(const _IteratorTriple& __other) const
194*e4b17023SJohn Marino       { return _M_first - __other._M_first; }
195*e4b17023SJohn Marino   };
196*e4b17023SJohn Marino }
197*e4b17023SJohn Marino 
198*e4b17023SJohn Marino #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */
199