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