libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file parallel/iterator.h 00026 * @brief Helper iterator classes for the std::transform() functions. 00027 * This file is a GNU parallel extension to the Standard C++ Library. 00028 */ 00029 00030 // Written by Johannes Singler. 00031 00032 #ifndef _GLIBCXX_PARALLEL_ITERATOR_H 00033 #define _GLIBCXX_PARALLEL_ITERATOR_H 1 00034 00035 #include <parallel/basic_iterator.h> 00036 #include <bits/stl_pair.h> 00037 00038 namespace __gnu_parallel 00039 { 00040 /** @brief A pair of iterators. The usual iterator operations are 00041 * applied to both child iterators. 00042 */ 00043 template<typename Iterator1, typename Iterator2, typename IteratorCategory> 00044 class iterator_pair : public std::pair<Iterator1, Iterator2> 00045 { 00046 private: 00047 typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type; 00048 typedef std::pair<Iterator1, Iterator2> base_type; 00049 00050 public: 00051 typedef IteratorCategory iterator_category; 00052 typedef void value_type; 00053 00054 typedef std::iterator_traits<Iterator1> traits_type; 00055 typedef typename traits_type::difference_type difference_type; 00056 typedef type* pointer; 00057 typedef type& reference; 00058 00059 iterator_pair() { } 00060 00061 iterator_pair(const Iterator1& first, const Iterator2& second) 00062 : base_type(first, second) { } 00063 00064 // Pre-increment operator. 00065 type& 00066 operator++() 00067 { 00068 ++base_type::first; 00069 ++base_type::second; 00070 return *this; 00071 } 00072 00073 // Post-increment operator. 00074 const type 00075 operator++(int) 00076 { return type(base_type::first++, base_type::second++); } 00077 00078 // Pre-decrement operator. 00079 type& 00080 operator--() 00081 { 00082 --base_type::first; 00083 --base_type::second; 00084 return *this; 00085 } 00086 00087 // Post-decrement operator. 00088 const type 00089 operator--(int) 00090 { return type(base_type::first--, base_type::second--); } 00091 00092 // Type conversion. 00093 operator Iterator2() const 00094 { return base_type::second; } 00095 00096 type& 00097 operator=(const type& other) 00098 { 00099 base_type::first = other.first; 00100 base_type::second = other.second; 00101 return *this; 00102 } 00103 00104 type 00105 operator+(difference_type delta) const 00106 { return type(base_type::first + delta, base_type::second + delta); } 00107 00108 difference_type 00109 operator-(const type& other) const 00110 { return base_type::first - other.first; } 00111 }; 00112 00113 00114 /** @brief A triple of iterators. The usual iterator operations are 00115 applied to all three child iterators. 00116 */ 00117 template<typename Iterator1, typename Iterator2, typename Iterator3, 00118 typename IteratorCategory> 00119 class iterator_triple 00120 { 00121 private: 00122 typedef iterator_triple<Iterator1, Iterator2, Iterator3, 00123 IteratorCategory> type; 00124 00125 public: 00126 typedef IteratorCategory iterator_category; 00127 typedef void value_type; 00128 typedef typename std::iterator_traits<Iterator1>::difference_type 00129 difference_type; 00130 typedef type* pointer; 00131 typedef type& reference; 00132 00133 Iterator1 first; 00134 Iterator2 second; 00135 Iterator3 third; 00136 00137 iterator_triple() { } 00138 00139 iterator_triple(const Iterator1& _first, const Iterator2& _second, 00140 const Iterator3& _third) 00141 { 00142 first = _first; 00143 second = _second; 00144 third = _third; 00145 } 00146 00147 // Pre-increment operator. 00148 type& 00149 operator++() 00150 { 00151 ++first; 00152 ++second; 00153 ++third; 00154 return *this; 00155 } 00156 00157 // Post-increment operator. 00158 const type 00159 operator++(int) 00160 { return type(first++, second++, third++); } 00161 00162 // Pre-decrement operator. 00163 type& 00164 operator--() 00165 { 00166 --first; 00167 --second; 00168 --third; 00169 return *this; 00170 } 00171 00172 // Post-decrement operator. 00173 const type 00174 operator--(int) 00175 { return type(first--, second--, third--); } 00176 00177 // Type conversion. 00178 operator Iterator3() const 00179 { return third; } 00180 00181 type& 00182 operator=(const type& other) 00183 { 00184 first = other.first; 00185 second = other.second; 00186 third = other.third; 00187 return *this; 00188 } 00189 00190 type 00191 operator+(difference_type delta) const 00192 { return type(first + delta, second + delta, third + delta); } 00193 00194 difference_type 00195 operator-(const type& other) const 00196 { return first - other.first; } 00197 }; 00198 } 00199 00200 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */