// ============================================================================ // // Copyright (c) 2003 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------------- // // release : $CGAL_Revision: $ // release_date : $CGAL_Date: $ // // file : Iterator_identity.h // chapter : $CGAL_Chapter: STL Extensions for CGAL $ // package : $CGAL_Package: STL_Extension $ // source : stl_extension.fw // revision : $Revision$ // revision_date : $Date$ // author(s) : Michael Hoffmann // Lutz Kettner // Sylvain Pion // // maintainer : Michael Hoffmann // coordinator : ETH // // An iterator adaptor for the identity function. // ============================================================================ #ifndef CGAL_ITERATOR_IDENTITY_H #define CGAL_ITERATOR_IDENTITY_H 1 #include CGAL_BEGIN_NAMESPACE template < class I, class Ref = typename std::iterator_traits::reference, class Ptr = typename std::iterator_traits::pointer, class Val = typename std::iterator_traits::value_type, class Dist = typename std::iterator_traits::difference_type, class Ctg = typename std::iterator_traits::iterator_category> class Iterator_identity { protected: I nt; // The internal iterator. public: typedef I Iterator; typedef Iterator_identity Self; typedef Ctg iterator_category; typedef Val value_type; typedef Dist difference_type; typedef Ref reference; typedef Ptr pointer; // CREATION // -------- Iterator_identity() {} Iterator_identity( Iterator j) : nt(j) {} // OPERATIONS Forward Category // --------------------------- Iterator current_iterator() const { return nt;} bool operator==( const Self& i) const { return ( nt == i.nt); //###// } bool operator!=( const Self& i) const { return !(*this == i); } Ref operator*() const { return *nt; //###// } Ptr operator->() const { return nt.operator->(); //###// } Self& operator++() { ++nt; //###// return *this; } Self operator++(int) { Self tmp = *this; ++*this; return tmp; } // OPERATIONS Bidirectional Category // --------------------------------- Self& operator--() { --nt; //###// return *this; } Self operator--(int) { Self tmp = *this; --*this; return tmp; } // OPERATIONS Random Access Category // --------------------------------- Self& operator+=( difference_type n) { nt += n; //###// return *this; } Self operator+( difference_type n) const { Self tmp = *this; return tmp += n; } Self& operator-=( difference_type n) { return operator+=( -n); } Self operator-( difference_type n) const { Self tmp = *this; return tmp += -n; } difference_type operator-( const Self& i) const { return nt - i.nt; //###// } Ref operator[]( difference_type n) const { Self tmp = *this; tmp += n; return tmp.operator*(); } bool operator<( const Self& i) const { return ( nt < i.nt); //###// } bool operator>( const Self& i) const { return i < *this; } bool operator<=( const Self& i) const { return !(i < *this); } bool operator>=( const Self& i) const { return !(*this < i); } }; template < class I, class Ref, class Ptr, class Val, class Dist, class Ctg> inline Iterator_identity operator+( Dist n, Iterator_identity i) { return i += n; } CGAL_END_NAMESPACE #endif // CGAL_ITERATOR_IDENTITY_H // // EOF //