ivl 679
ivl/details/core/tool/same_place_reverse_iterator.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 #ifndef IVL_CORE_DETAILS_TOOL_SAME_PLACE_REVERSE_ITERATOR_HPP
00025 #define IVL_CORE_DETAILS_TOOL_SAME_PLACE_REVERSE_ITERATOR_HPP
00026 
00027 namespace ivl {
00028 
00029 // same place reverse iterators
00053   template<typename _Iterator>
00054     class same_place_reverse_iterator
00055     : public std::iterator<typename std::iterator_traits<_Iterator>
00056                 ::iterator_category,
00057                       typename std::iterator_traits<_Iterator>::value_type,
00058                       typename std::iterator_traits<_Iterator>::difference_type,
00059                       typename std::iterator_traits<_Iterator>::pointer,
00060                       typename std::iterator_traits<_Iterator>::reference>
00061     {
00062     protected:
00063       _Iterator current;
00064 
00065     public:
00066       typedef _Iterator                                        iterator_type;
00067       typedef typename std::iterator_traits<_Iterator>::difference_type
00068                                                                difference_type;
00069       typedef typename std::iterator_traits<_Iterator>::reference   reference;
00070       typedef typename std::iterator_traits<_Iterator>::pointer     pointer;
00071 
00072     public:
00077       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00078       // 235 No specification of default ctor for same_place_reverse_iterator
00079       same_place_reverse_iterator() : current() { }
00080 
00084       explicit
00085       same_place_reverse_iterator(iterator_type __x) : current(__x) { }
00086 
00090       same_place_reverse_iterator(const same_place_reverse_iterator& __x)
00091       : current(__x.current) { }
00092 
00097       template<typename _Iter>
00098         same_place_reverse_iterator(const same_place_reverse_iterator<_Iter>& __x)
00099         : current(__x.base()) { }
00100 
00104       iterator_type
00105       base() const
00106       { return current; }
00107 
00113       reference
00114       operator*() //const
00115       {
00116         //This is the only difference for same_place_reverse_iterator
00117         return *current;
00118       }
00119 
00125       pointer
00126       operator->() const
00127       { return &(operator*()); }
00128 
00134       same_place_reverse_iterator&
00135       operator++()
00136       {
00137         --current;
00138         return *this;
00139       }
00140 
00146       same_place_reverse_iterator
00147       operator++(int)
00148       {
00149         same_place_reverse_iterator __tmp = *this;
00150         --current;
00151         return __tmp;
00152       }
00153 
00159       same_place_reverse_iterator&
00160       operator--()
00161       {
00162         ++current;
00163         return *this;
00164       }
00165 
00171       same_place_reverse_iterator
00172       operator--(int)
00173       {
00174         same_place_reverse_iterator __tmp = *this;
00175         ++current;
00176         return __tmp;
00177       }
00178 
00184       same_place_reverse_iterator
00185       operator+(difference_type __n) const
00186       { return same_place_reverse_iterator(current - __n); }
00187 
00193       same_place_reverse_iterator&
00194       operator+=(difference_type __n)
00195       {
00196         current -= __n;
00197         return *this;
00198       }
00199 
00205       same_place_reverse_iterator
00206       operator-(difference_type __n) const
00207       { return same_place_reverse_iterator(current + __n); }
00208 
00214       same_place_reverse_iterator&
00215       operator-=(difference_type __n)
00216       {
00217         current += __n;
00218         return *this;
00219       }
00220 
00226       reference
00227       operator[](difference_type __n) const
00228       { return *(*this + __n); }
00229     };
00230 
00232 
00241   template<typename _Iterator>
00242     inline bool
00243     operator==(const same_place_reverse_iterator<_Iterator>& __x,
00244                const same_place_reverse_iterator<_Iterator>& __y)
00245     { return __x.base() == __y.base(); }
00246 
00247   template<typename _Iterator>
00248     inline bool
00249     operator<(const same_place_reverse_iterator<_Iterator>& __x,
00250               const same_place_reverse_iterator<_Iterator>& __y)
00251     { return __y.base() < __x.base(); }
00252 
00253   template<typename _Iterator>
00254     inline bool
00255     operator!=(const same_place_reverse_iterator<_Iterator>& __x,
00256                const same_place_reverse_iterator<_Iterator>& __y)
00257     { return !(__x == __y); }
00258 
00259   template<typename _Iterator>
00260     inline bool
00261     operator>(const same_place_reverse_iterator<_Iterator>& __x,
00262               const same_place_reverse_iterator<_Iterator>& __y)
00263     { return __y < __x; }
00264 
00265   template<typename _Iterator>
00266     inline bool
00267     operator<=(const same_place_reverse_iterator<_Iterator>& __x,
00268                const same_place_reverse_iterator<_Iterator>& __y)
00269     { return !(__y < __x); }
00270 
00271   template<typename _Iterator>
00272     inline bool
00273     operator>=(const same_place_reverse_iterator<_Iterator>& __x,
00274                const same_place_reverse_iterator<_Iterator>& __y)
00275     { return !(__x < __y); }
00276 
00277   template<typename _Iterator>
00278     inline typename same_place_reverse_iterator<_Iterator>::difference_type
00279     operator-(const same_place_reverse_iterator<_Iterator>& __x,
00280               const same_place_reverse_iterator<_Iterator>& __y)
00281     { return __y.base() - __x.base(); }
00282 
00283   template<typename _Iterator>
00284     inline same_place_reverse_iterator<_Iterator>
00285     operator+(typename same_place_reverse_iterator<_Iterator>::difference_type __n,
00286               const same_place_reverse_iterator<_Iterator>& __x)
00287     { return same_place_reverse_iterator<_Iterator>(__x.base() - __n); }
00288 
00289   // _GLIBCXX_RESOLVE_LIB_DEFECTS
00290   // DR 280. Comparison of same_place_reverse_iterator to const same_place_reverse_iterator.
00291   template<typename _IteratorL, typename _IteratorR>
00292     inline bool
00293     operator==(const same_place_reverse_iterator<_IteratorL>& __x,
00294                const same_place_reverse_iterator<_IteratorR>& __y)
00295     { return __x.base() == __y.base(); }
00296 
00297   template<typename _IteratorL, typename _IteratorR>
00298     inline bool
00299     operator<(const same_place_reverse_iterator<_IteratorL>& __x,
00300               const same_place_reverse_iterator<_IteratorR>& __y)
00301     { return __y.base() < __x.base(); }
00302 
00303   template<typename _IteratorL, typename _IteratorR>
00304     inline bool
00305     operator!=(const same_place_reverse_iterator<_IteratorL>& __x,
00306                const same_place_reverse_iterator<_IteratorR>& __y)
00307     { return !(__x == __y); }
00308 
00309   template<typename _IteratorL, typename _IteratorR>
00310     inline bool
00311     operator>(const same_place_reverse_iterator<_IteratorL>& __x,
00312               const same_place_reverse_iterator<_IteratorR>& __y)
00313     { return __y < __x; }
00314 
00315   template<typename _IteratorL, typename _IteratorR>
00316     inline bool
00317     operator<=(const same_place_reverse_iterator<_IteratorL>& __x,
00318                const same_place_reverse_iterator<_IteratorR>& __y)
00319     { return !(__y < __x); }
00320 
00321   template<typename _IteratorL, typename _IteratorR>
00322     inline bool
00323     operator>=(const same_place_reverse_iterator<_IteratorL>& __x,
00324                const same_place_reverse_iterator<_IteratorR>& __y)
00325     { return !(__x < __y); }
00326 
00327   template<typename _IteratorL, typename _IteratorR>
00328 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00329     // DR 685.
00330     inline auto
00331     operator-(const same_place_reverse_iterator<_IteratorL>& __x,
00332               const same_place_reverse_iterator<_IteratorR>& __y)
00333     -> decltype(__y.base() - __x.base())
00334 #else
00335     inline typename same_place_reverse_iterator<_IteratorL>::difference_type
00336     operator-(const same_place_reverse_iterator<_IteratorL>& __x,
00337               const same_place_reverse_iterator<_IteratorR>& __y)
00338 #endif
00339     { return __y.base() - __x.base(); }
00341 
00342 } /* namespace ivl */
00343 
00344 #endif // IVL_CORE_DETAILS_TOOL_SAME_PLACE_REVERSE_ITERATOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations