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 Iterator1::difference_type difference_type;
00135       typedef type* pointer;
00136       typedef type& reference;
00137 
00138       Iterator1 first;
00139       Iterator2 second;
00140       Iterator3 third;
00141 
00142       iterator_triple() { }
00143 
00144       iterator_triple(const Iterator1& _first, const Iterator2& _second,
00145               const Iterator3& _third)
00146       {
00147     first = _first;
00148     second = _second;
00149     third = _third;
00150       }
00151 
00152       // Pre-increment operator.
00153       type&
00154       operator++()
00155       {
00156     ++first;
00157     ++second;
00158     ++third;
00159     return *this;
00160       }
00161 
00162       // Post-increment operator.
00163       const type
00164       operator++(int)
00165       { return type(first++, second++, third++); }
00166 
00167       // Pre-decrement operator.
00168       type&
00169       operator--()
00170       {
00171     --first;
00172     --second;
00173     --third;
00174     return *this;
00175       }
00176 
00177       // Post-decrement operator.
00178       const type
00179       operator--(int)
00180       { return type(first--, second--, third--); }
00181 
00182       // Type conversion.
00183       operator Iterator3() const
00184       { return third; }
00185 
00186       type&
00187       operator=(const type& other)
00188       {
00189     first = other.first;
00190     second = other.second;
00191     third = other.third;
00192     return *this;
00193       }
00194 
00195       type
00196       operator+(difference_type delta) const
00197       { return type(first + delta, second + delta, third + delta); }
00198 
00199       difference_type
00200       operator-(const type& other) const
00201       { return first - other.first; }
00202   };
00203 }
00204 
00205 #endif

Generated on Wed Dec 31 12:48:56 2008 for libstdc++ by  doxygen 1.5.6