stlab.adobe.com Adobe Systems Incorporated

value_iterator.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_ITERATOR_VALUE_ITERATOR_HPP
00010 #define ADOBE_ITERATOR_VALUE_ITERATOR_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <adobe/functional.hpp>
00015 
00016 #include <functional>
00017 #include <iterator>
00018 #include <cassert>
00019 
00020 /*************************************************************************************************/
00021 
00022 namespace adobe {
00023 
00024 /*************************************************************************************************/
00025 
00028 
00029 
00030 template <typename I,                // I models Incrementable    
00031           typename F = identity<I> > // F models UnaryFunction 
00032 class value_iterator
00033 {
00034 public:
00035     typedef typename F::result_type   value_type;
00036     typedef value_type*               pointer;
00037     typedef value_type&               reference;
00038     typedef ptrdiff_t                 difference_type;
00039     typedef std::forward_iterator_tag iterator_category;
00040 
00041 private:
00042     I i;
00043     F f;
00044 
00045 public:
00046     value_iterator()
00047     { }
00048 
00049     value_iterator(const I& x, const F& y) :
00050         i(x), f(y)
00051     { }
00052 
00053     value_iterator& operator++()
00054     {
00055         ++i;
00056         return *this;
00057     }
00058 
00059     value_iterator operator++(int)
00060     {
00061         value_iterator tmp = *this;
00062 
00063         ++*this;
00064 
00065         return tmp;
00066     }
00067 
00068     const value_type& operator*() const
00069     {
00070         return f(i);
00071     }
00072 
00073     value_type operator*()
00074     {
00075         return f(i);
00076     }
00077 
00078     friend bool operator==(const value_iterator& a, const value_iterator& b)
00079     {
00080         // assert(a.f == b.f);
00081 
00082         return a.i == b.i;
00083     }
00084 
00085     friend bool operator!=(const value_iterator& a, const value_iterator& b)
00086     {
00087         return !(a == b);
00088     }
00089 };
00090 
00092 
00093 /*************************************************************************************************/
00094 
00095 } // namespace adobe
00096 
00097 /*************************************************************************************************/
00098 
00099 #endif
00100 // ADOBE_ITERATOR_DISTANCE_HPP

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google