Debian Codegraph @

cutl/container/map-iterator.hxx

raw
1 // file : cutl/container/map-iterator.hxx
2 // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
3 // license : MIT; see accompanying LICENSE file
4
5 #ifndef CUTL_CONTAINER_MAP_ITERATOR_HXX
6 #define CUTL_CONTAINER_MAP_ITERATOR_HXX
7
8 namespace cutl
9 {
10 namespace container
11 {
12 // Map iterator adapter that can be used to implement multi-index
13 // containers, as discussed in the following post:
14 //
15 // http://www.codesynthesis.com/~boris/blog/2012/09/11/emulating-boost-multi-index-with-std-containers/
16 //
17 template <typename M>
18 struct map_iterator: M::iterator
19 {
20 typedef typename M::iterator base_iterator;
21 typedef typename M::value_type::second_type value_type;
22 typedef value_type* pointer;
23 typedef value_type& reference;
24
25 map_iterator () {}
26 map_iterator (base_iterator i): base_iterator (i) {}
27
28 reference
29 operator* () const
30 {
31 return base_iterator::operator* ().second;
32 }
33
34 pointer
35 operator-> () const
36 {
37 return &base_iterator::operator-> ()->second;
38 }
39 };
40
41 template <typename M>
42 struct map_const_iterator: M::const_iterator
43 {
44 typedef typename M::iterator base_iterator;
45 typedef typename M::const_iterator base_const_iterator;
46 typedef const typename M::value_type::second_type value_type;
47 typedef value_type* pointer;
48 typedef value_type& reference;
49
50 map_const_iterator () {}
51 map_const_iterator (base_iterator i): base_const_iterator (i) {}
52 map_const_iterator (base_const_iterator i): base_const_iterator (i) {}
53
54 reference
55 operator* () const
56 {
57 return base_const_iterator::operator* ().second;
58 }
59
60 pointer
61 operator-> () const
62 {
63 return &base_const_iterator::operator-> ()->second;
64 }
65 };
66 }
67 }
68
69 #endif // CUTL_CONTAINER_MAP_ITERATOR_HXX