summaryrefslogtreecommitdiff
path: root/libcutl/cutl/container/map-iterator.hxx
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 15:21:29 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 15:21:29 +0200
commitbada6666c70977a058755ccf232e7d67b24adeed (patch)
tree1e92d50cebce96abaf9bce19e36026c47f77b9ba /libcutl/cutl/container/map-iterator.hxx
parenteaf34adcbd8095bc6d1f3371b1227f654c7b19fc (diff)
New upstream release
Diffstat (limited to 'libcutl/cutl/container/map-iterator.hxx')
-rw-r--r--libcutl/cutl/container/map-iterator.hxx69
1 files changed, 69 insertions, 0 deletions
diff --git a/libcutl/cutl/container/map-iterator.hxx b/libcutl/cutl/container/map-iterator.hxx
new file mode 100644
index 0000000..051ffb5
--- /dev/null
+++ b/libcutl/cutl/container/map-iterator.hxx
@@ -0,0 +1,69 @@
+// file : cutl/container/map-iterator.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CUTL_CONTAINER_MAP_ITERATOR_HXX
+#define CUTL_CONTAINER_MAP_ITERATOR_HXX
+
+namespace cutl
+{
+ namespace container
+ {
+ // Map iterator adapter that can be used to implement multi-index
+ // containers, as discussed in the following post:
+ //
+ // http://www.codesynthesis.com/~boris/blog/2012/09/11/emulating-boost-multi-index-with-std-containers/
+ //
+ template <typename M>
+ struct map_iterator: M::iterator
+ {
+ typedef typename M::iterator base_iterator;
+ typedef typename M::value_type::second_type value_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ map_iterator () {}
+ map_iterator (base_iterator i): base_iterator (i) {}
+
+ reference
+ operator* () const
+ {
+ return base_iterator::operator* ().second;
+ }
+
+ pointer
+ operator-> () const
+ {
+ return &base_iterator::operator-> ()->second;
+ }
+ };
+
+ template <typename M>
+ struct map_const_iterator: M::const_iterator
+ {
+ typedef typename M::iterator base_iterator;
+ typedef typename M::const_iterator base_const_iterator;
+ typedef const typename M::value_type::second_type value_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ map_const_iterator () {}
+ map_const_iterator (base_iterator i): base_const_iterator (i) {}
+ map_const_iterator (base_const_iterator i): base_const_iterator (i) {}
+
+ reference
+ operator* () const
+ {
+ return base_const_iterator::operator* ().second;
+ }
+
+ pointer
+ operator-> () const
+ {
+ return &base_const_iterator::operator-> ()->second;
+ }
+ };
+ }
+}
+
+#endif // CUTL_CONTAINER_MAP_ITERATOR_HXX