diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-16 20:29:05 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-02-24 16:40:04 +0300 |
commit | 8e761289a2446367267c6c0d9a26e734f0f78306 (patch) | |
tree | fb495d8c18801f271d124ee48731f10df396ca89 /libcutl/container/map-iterator.hxx | |
parent | 4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff) |
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/container/map-iterator.hxx')
-rw-r--r-- | libcutl/container/map-iterator.hxx | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libcutl/container/map-iterator.hxx b/libcutl/container/map-iterator.hxx new file mode 100644 index 0000000..a5b65e8 --- /dev/null +++ b/libcutl/container/map-iterator.hxx @@ -0,0 +1,68 @@ +// file : libcutl/container/map-iterator.hxx +// license : MIT; see accompanying LICENSE file + +#ifndef LIBCUTL_CONTAINER_MAP_ITERATOR_HXX +#define LIBCUTL_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 // LIBCUTL_CONTAINER_MAP_ITERATOR_HXX |