# iterator.h

Go to the documentation of this file.

    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,
    00044            typename _IteratorCategory>
    00045     class _IteratorPair : public std::pair<_Iterator1, _Iterator2>
    00046     {
    00047     private:
    00048       typedef std::pair<_Iterator1, _Iterator2> _Base;
    00049
    00050     public:
    00051       typedef _IteratorCategory iterator_category;
    00052       typedef void value_type;
    00053
    00054       typedef std::iterator_traits<_Iterator1> _TraitsType;
    00055       typedef typename _TraitsType::difference_type difference_type;
    00056       typedef _IteratorPair* pointer;
    00057       typedef _IteratorPair& reference;
    00058
    00059       _IteratorPair() { }
    00060
    00061       _IteratorPair(const _Iterator1& __first, const _Iterator2& __second)
    00062       : _Base(__first, __second) { }
    00063
    00064       // Pre-increment operator.
    00065       _IteratorPair&
    00066       operator++()
    00067       {
    00068         ++_Base::first;
    00069         ++_Base::second;
    00070         return *this;
    00071       }
    00072
    00073       // Post-increment operator.
    00074       const _IteratorPair
    00075       operator++(int)
    00076       { return _IteratorPair(_Base::first++, _Base::second++); }
    00077
    00078       // Pre-decrement operator.
    00079       _IteratorPair&
    00080       operator--()
    00081       {
    00082         --_Base::first;
    00083         --_Base::second;
    00084         return *this;
    00085       }
    00086
    00087       // Post-decrement operator.
    00088       const _IteratorPair
    00089       operator--(int)
    00090       { return _IteratorPair(_Base::first--, _Base::second--); }
    00091
    00092       // Type conversion.
    00093       operator _Iterator2() const
    00094       { return _Base::second; }
    00095
    00096       _IteratorPair&
    00097       operator=(const _IteratorPair& __other)
    00098       {
    00099         _Base::first = __other.first;
    00100         _Base::second = __other.second;
    00101         return *this;
    00102       }
    00103
    00104       _IteratorPair
    00105       operator+(difference_type __delta) const
    00106       { return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
    00107         }
    00108
    00109       difference_type
    00110       operator-(const _IteratorPair& __other) const
    00111       { return _Base::first - __other.first; }
    00112   };
    00113
    00114
    00115   /** @brief A triple of iterators. The usual iterator operations are
    00116       applied to all three child iterators.
    00117    */
    00118   template<typename _Iterator1, typename _Iterator2, typename _Iterator3,
    00119            typename _IteratorCategory>
    00120     class _IteratorTriple
    00121     {
    00122     public:
    00123       typedef _IteratorCategory iterator_category;
    00124       typedef void value_type;
    00125       typedef typename std::iterator_traits<_Iterator1>::difference_type
    00126                                                             difference_type;
    00127       typedef _IteratorTriple* pointer;
    00128       typedef _IteratorTriple& reference;
    00129
    00130       _Iterator1 _M_first;
    00131       _Iterator2 _M_second;
    00132       _Iterator3 _M_third;
    00133
    00134       _IteratorTriple() { }
    00135
    00136       _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second,
    00137                       const _Iterator3& __third)
    00138       {
    00139         _M_first = __first;
    00140         _M_second = __second;
    00141         _M_third = __third;
    00142       }
    00143
    00144       // Pre-increment operator.
    00145       _IteratorTriple&
    00146       operator++()
    00147       {
    00148         ++_M_first;
    00149         ++_M_second;
    00150         ++_M_third;
    00151         return *this;
    00152       }
    00153
    00154       // Post-increment operator.
    00155       const _IteratorTriple
    00156       operator++(int)
    00157       { return _IteratorTriple(_M_first++, _M_second++, _M_third++); }
    00158
    00159       // Pre-decrement operator.
    00160       _IteratorTriple&
    00161       operator--()
    00162       {
    00163         --_M_first;
    00164         --_M_second;
    00165         --_M_third;
    00166         return *this;
    00167       }
    00168
    00169       // Post-decrement operator.
    00170       const _IteratorTriple
    00171       operator--(int)
    00172       { return _IteratorTriple(_M_first--, _M_second--, _M_third--); }
    00173
    00174       // Type conversion.
    00175       operator _Iterator3() const
    00176       { return _M_third; }
    00177
    00178       _IteratorTriple&
    00179       operator=(const _IteratorTriple& __other)
    00180       {
    00181         _M_first = __other._M_first;
    00182         _M_second = __other._M_second;
    00183         _M_third = __other._M_third;
    00184         return *this;
    00185       }
    00186
    00187       _IteratorTriple
    00188       operator+(difference_type __delta) const
    00189       { return _IteratorTriple(_M_first + __delta, _M_second + __delta,
    00190                                _M_third + __delta); }
    00191
    00192       difference_type
    00193       operator-(const _IteratorTriple& __other) const
    00194       { return _M_first - __other._M_first; }
    00195   };
    00196 }
    00197
    00198 #endif /* _GLIBCXX_PARALLEL_ITERATOR_H */