iterator.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008 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 2, 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 // You should have received a copy of the GNU General Public License
00017 // along with this library; see the file COPYING.  If not, write to
00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00019 // MA 02111-1307, USA.
00020 
00021 // As a special exception, you may use this file as part of a free
00022 // software library without restriction.  Specifically, if other files
00023 // instantiate templates or use macros or inline functions from this
00024 // file, or you compile this file and link it with other files to
00025 // produce an executable, this file does not by itself cause the
00026 // resulting executable to be covered by the GNU General Public
00027 // License.  This exception does not however invalidate any other
00028 // reasons why the executable file might be covered by the GNU General
00029 // Public License.
00030 
00031 /** @file parallel/iterator.h
00032  * @brief Helper iterator classes for the std::transform() functions.
00033  *  This file is a GNU parallel extension to the Standard C++ Library.
00034  */
00035 
00036 // Written by Johannes Singler.
00037 
00038 #ifndef _GLIBCXX_PARALLEL_ITERATOR_H
00039 #define _GLIBCXX_PARALLEL_ITERATOR_H 1
00040 
00041 #include <parallel/basic_iterator.h>
00042 #include <bits/stl_pair.h>
00043 
00044 namespace __gnu_parallel
00045 {
00046   /** @brief A pair of iterators. The usual iterator operations are
00047    *  applied to both child iterators.
00048    */
00049   template<typename Iterator1, typename Iterator2, typename IteratorCategory>
00050     class iterator_pair : public std::pair<Iterator1, Iterator2>
00051     {
00052     private:
00053       typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type;
00054       typedef std::pair<Iterator1, Iterator2> base_type;
00055 
00056     public:
00057       typedef IteratorCategory iterator_category;
00058       typedef void value_type;
00059 
00060       typedef std::iterator_traits<Iterator1> traits_type;
00061       typedef typename traits_type::difference_type difference_type;
00062       typedef type* pointer;
00063       typedef type& reference;
00064 
00065       iterator_pair() { }
00066 
00067       iterator_pair(const Iterator1& first, const Iterator2& second) 
00068       : base_type(first, second) { }
00069 
00070       // Pre-increment operator.
00071       type&
00072       operator++()
00073       {
00074     ++base_type::first;
00075     ++base_type::second;
00076     return *this;
00077       }
00078 
00079       // Post-increment operator.
00080       const type
00081       operator++(int)
00082       { return type(base_type::first++, base_type::second++); }
00083 
00084       // Pre-decrement operator.
00085       type&
00086       operator--()
00087       {
00088     --base_type::first;
00089     --base_type::second;
00090     return *this;
00091       }
00092 
00093       // Post-decrement operator.
00094       const type
00095       operator--(int)
00096       { return type(base_type::first--, base_type::second--); }
00097 
00098       // Type conversion.
00099       operator Iterator2() const
00100       { return base_type::second; }
00101 
00102       type&
00103       operator=(const type& other)
00104       {
00105     base_type::first = other.first;
00106     base_type::second = other.second;
00107     return *this;
00108       }
00109 
00110       type
00111       operator+(difference_type delta) const
00112       { return type(base_type::first + delta, base_type::second + delta); }
00113 
00114       difference_type
00115       operator-(const type& other) const
00116       { return base_type::first - other.first; }
00117   };
00118 
00119 
00120   /** @brief A triple of iterators. The usual iterator operations are
00121       applied to all three child iterators.
00122    */
00123   template<typename Iterator1, typename Iterator2, typename Iterator3,
00124        typename IteratorCategory>
00125     class iterator_triple
00126     {
00127     private:
00128       typedef iterator_triple<Iterator1, Iterator2, Iterator3,
00129                   IteratorCategory> type;
00130 
00131     public:
00132       typedef IteratorCategory iterator_category;
00133       typedef void value_type;
00134       typedef typename std::iterator_traits<Iterator1>::difference_type
00135                                                             difference_type;
00136       typedef type* pointer;
00137       typedef type& reference;
00138 
00139       Iterator1 first;
00140       Iterator2 second;
00141       Iterator3 third;
00142 
00143       iterator_triple() { }
00144 
00145       iterator_triple(const Iterator1& _first, const Iterator2& _second,
00146               const Iterator3& _third)
00147       {
00148     first = _first;
00149     second = _second;
00150     third = _third;
00151       }
00152 
00153       // Pre-increment operator.
00154       type&
00155       operator++()
00156       {
00157     ++first;
00158     ++second;
00159     ++third;
00160     return *this;
00161       }
00162 
00163       // Post-increment operator.
00164       const type
00165       operator++(int)
00166       { return type(first++, second++, third++); }
00167 
00168       // Pre-decrement operator.
00169       type&
00170       operator--()
00171       {
00172     --first;
00173     --second;
00174     --third;
00175     return *this;
00176       }
00177 
00178       // Post-decrement operator.
00179       const type
00180       operator--(int)
00181       { return type(first--, second--, third--); }
00182 
00183       // Type conversion.
00184       operator Iterator3() const
00185       { return third; }
00186 
00187       type&
00188       operator=(const type& other)
00189       {
00190     first = other.first;
00191     second = other.second;
00192     third = other.third;
00193     return *this;
00194       }
00195 
00196       type
00197       operator+(difference_type delta) const
00198       { return type(first + delta, second + delta, third + delta); }
00199 
00200       difference_type
00201       operator-(const type& other) const
00202       { return first - other.first; }
00203   };
00204 }
00205 
00206 #endif

Generated on Sat Dec 12 09:40:11 2009 for libstdc++ by  doxygen 1.5.6