diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
commit | 8286ac511144e4f17d34eac9affb97e50646344a (patch) | |
tree | f1af7320d7b6be6be059216d0ad08ac7b4f73fd0 /libcutl/cutl/container/pointer-iterator.hxx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'libcutl/cutl/container/pointer-iterator.hxx')
-rw-r--r-- | libcutl/cutl/container/pointer-iterator.hxx | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/libcutl/cutl/container/pointer-iterator.hxx b/libcutl/cutl/container/pointer-iterator.hxx new file mode 100644 index 0000000..7059558 --- /dev/null +++ b/libcutl/cutl/container/pointer-iterator.hxx @@ -0,0 +1,126 @@ +// file : cutl/container/pointer-iterator.hxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CUTL_CONTAINER_POINTER_ITERATOR_HXX +#define CUTL_CONTAINER_POINTER_ITERATOR_HXX + +#include <iterator> // std::iterator_traits + +#include <cutl/meta/remove-p.hxx> + +namespace cutl +{ + namespace container + { + template <typename I> + class pointer_iterator + { + public: + typedef + typename meta::remove_p<typename std::iterator_traits<I>::value_type>::r + value_type; + + typedef + typename std::iterator_traits<I>::iterator_category + iterator_category; + + typedef + typename std::iterator_traits<I>::difference_type + difference_type; + + typedef value_type& reference; + typedef value_type* pointer; + typedef I base_iterator; + + public: + pointer_iterator () + : i_ () // I can be of a pointer type. + { + } + + pointer_iterator (I const& i) + : i_ (i) + { + } + + public: + reference + operator* () const + { + return **i_; + } + + pointer + operator-> () const + { + return *i_; + } + + I const& + base () const + { + return i_; + } + + public: + // Forward iterator requirements. + // + pointer_iterator& + operator++ () + { + ++i_; + return *this; + } + + pointer_iterator + operator++ (int) + { + pointer_iterator r (*this); + ++i_; + return r; + } + + pointer_iterator& + operator-- () + { + --i_; + return *this; + } + + pointer_iterator + operator-- (int) + { + pointer_iterator r (*this); + --i_; + return r; + } + + private: + I i_; + }; + + template <typename I> + inline bool + operator== (pointer_iterator<I> const& a, pointer_iterator<I> const& b) + { + return a.base () == b.base (); + } + + template <typename I> + inline bool + operator!= (pointer_iterator<I> const& a, pointer_iterator<I> const& b) + { + return a.base () != b.base (); + } + + template <typename I> + inline typename pointer_iterator<I>::difference_type + operator- (pointer_iterator<I> const& a, pointer_iterator<I> const& b) + { + return a.base () - b.base (); + } + } +} + +#endif // CUTL_CONTAINER_POINTER_ITERATOR_HXX |