1 // -*- C++ -*- 2 3 // Copyright (C) 2007, 2008, 2009 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 // <http://www.gnu.org/licenses/>. 24 25 /** @file parallel/iterator.h 26 * @brief Helper iterator classes for the std::transform() functions. 27 * This file is a GNU parallel extension to the Standard C++ Library. 28 */ 29 30 // Written by Johannes Singler. 31 32 #ifndef _GLIBCXX_PARALLEL_ITERATOR_H 33 #define _GLIBCXX_PARALLEL_ITERATOR_H 1 34 35 #include <parallel/basic_iterator.h> 36 #include <bits/stl_pair.h> 37 38 namespace __gnu_parallel 39 { 40 /** @brief A pair of iterators. The usual iterator operations are 41 * applied to both child iterators. 42 */ 43 template<typename Iterator1, typename Iterator2, typename IteratorCategory> 44 class iterator_pair : public std::pair<Iterator1, Iterator2> 45 { 46 private: 47 typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type; 48 typedef std::pair<Iterator1, Iterator2> base_type; 49 50 public: 51 typedef IteratorCategory iterator_category; 52 typedef void value_type; 53 54 typedef std::iterator_traits<Iterator1> traits_type; 55 typedef typename traits_type::difference_type difference_type; 56 typedef type* pointer; 57 typedef type& reference; 58 59 iterator_pair() { } 60 61 iterator_pair(const Iterator1& first, const Iterator2& second) 62 : base_type(first, second) { } 63 64 // Pre-increment operator. 65 type& 66 operator++() 67 { 68 ++base_type::first; 69 ++base_type::second; 70 return *this; 71 } 72 73 // Post-increment operator. 74 const type 75 operator++(int) 76 { return type(base_type::first++, base_type::second++); } 77 78 // Pre-decrement operator. 79 type& 80 operator--() 81 { 82 --base_type::first; 83 --base_type::second; 84 return *this; 85 } 86 87 // Post-decrement operator. 88 const type 89 operator--(int) 90 { return type(base_type::first--, base_type::second--); } 91 92 // Type conversion. 93 operator Iterator2() const 94 { return base_type::second; } 95 96 type& 97 operator=(const type& other) 98 { 99 base_type::first = other.first; 100 base_type::second = other.second; 101 return *this; 102 } 103 104 type 105 operator+(difference_type delta) const 106 { return type(base_type::first + delta, base_type::second + delta); } 107 108 difference_type 109 operator-(const type& other) const 110 { return base_type::first - other.first; } 111 }; 112 113 114 /** @brief A triple of iterators. The usual iterator operations are 115 applied to all three child iterators. 116 */ 117 template<typename Iterator1, typename Iterator2, typename Iterator3, 118 typename IteratorCategory> 119 class iterator_triple 120 { 121 private: 122 typedef iterator_triple<Iterator1, Iterator2, Iterator3, 123 IteratorCategory> type; 124 125 public: 126 typedef IteratorCategory iterator_category; 127 typedef void value_type; 128 typedef typename std::iterator_traits<Iterator1>::difference_type 129 difference_type; 130 typedef type* pointer; 131 typedef type& reference; 132 133 Iterator1 first; 134 Iterator2 second; 135 Iterator3 third; 136 137 iterator_triple() { } 138 139 iterator_triple(const Iterator1& _first, const Iterator2& _second, 140 const Iterator3& _third) 141 { 142 first = _first; 143 second = _second; 144 third = _third; 145 } 146 147 // Pre-increment operator. 148 type& 149 operator++() 150 { 151 ++first; 152 ++second; 153 ++third; 154 return *this; 155 } 156 157 // Post-increment operator. 158 const type 159 operator++(int) 160 { return type(first++, second++, third++); } 161 162 // Pre-decrement operator. 163 type& 164 operator--() 165 { 166 --first; 167 --second; 168 --third; 169 return *this; 170 } 171 172 // Post-decrement operator. 173 const type 174 operator--(int) 175 { return type(first--, second--, third--); } 176 177 // Type conversion. 178 operator Iterator3() const 179 { return third; } 180 181 type& 182 operator=(const type& other) 183 { 184 first = other.first; 185 second = other.second; 186 third = other.third; 187 return *this; 188 } 189 190 type 191 operator+(difference_type delta) const 192 { return type(first + delta, second + delta, third + delta); } 193 194 difference_type 195 operator-(const type& other) const 196 { return first - other.first; } 197 }; 198 } 199 200 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */ 201