stlab.adobe.com Adobe Systems Incorporated
value_iterator.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ITERATOR_VALUE_ITERATOR_HPP
10 #define ADOBE_ITERATOR_VALUE_ITERATOR_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <adobe/functional.hpp>
15 
16 #include <functional>
17 #include <iterator>
18 #include <cassert>
19 
20 /*************************************************************************************************/
21 
22 namespace adobe {
23 
24 /*************************************************************************************************/
25 
28 
29 
30 template <typename I, // I models Incrementable
31  typename F = identity<I> > // F models UnaryFunction
33 {
34 public:
35  typedef typename F::result_type value_type;
36  typedef value_type* pointer;
37  typedef value_type& reference;
38  typedef ptrdiff_t difference_type;
39  typedef std::forward_iterator_tag iterator_category;
40 
41 private:
42  I i;
43  F f;
44 
45 public:
47  { }
48 
49  value_iterator(const I& x, const F& y) :
50  i(x), f(y)
51  { }
52 
54  {
55  ++i;
56  return *this;
57  }
58 
60  {
61  value_iterator tmp = *this;
62 
63  ++*this;
64 
65  return tmp;
66  }
67 
68  const value_type& operator*() const
69  {
70  return f(i);
71  }
72 
73  value_type operator*()
74  {
75  return f(i);
76  }
77 
78  friend bool operator==(const value_iterator& a, const value_iterator& b)
79  {
80  // assert(a.f == b.f);
81 
82  return a.i == b.i;
83  }
84 
85  friend bool operator!=(const value_iterator& a, const value_iterator& b)
86  {
87  return !(a == b);
88  }
89 };
90 
92 
93 /*************************************************************************************************/
94 
95 } // namespace adobe
96 
97 /*************************************************************************************************/
98 
99 #endif
100 // ADOBE_ITERATOR_DISTANCE_HPP
friend bool operator==(const value_iterator &a, const value_iterator &b)
F::result_type value_type
value_iterator operator++(int)
std::forward_iterator_tag iterator_category
friend bool operator!=(const value_iterator &a, const value_iterator &b)
value_iterator(const I &x, const F &y)
value_iterator & operator++()
const value_type & operator*() const

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