Radium Engine  1.5.20
Loading...
Searching...
No Matches
StdMapIterators.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <map>
8#include <type_traits> // conditionals
9#include <unordered_map>
10
11namespace Ra {
12namespace Core {
13namespace Utils {
14
21template <class Mapclass>
22struct map_keys {
23 using map_t = Mapclass;
24
25 struct iterator {
26 using realiterator_t = typename std::conditional<std::is_const<map_t>::value,
27 typename map_t::const_iterator,
28 typename map_t::iterator>::type;
30 realiterator_t under;
31
32 iterator( realiterator_t x ) : under( x ) {}
33
34 auto operator*() -> typename std::add_lvalue_reference<value_t>::type {
35 return under->first;
36 }
37 auto operator->() -> typename std::add_pointer<value_t>::type { return &under->first; }
38
39 bool operator!=( const iterator& o ) const { return under != o.under; }
40
41 iterator& operator++() {
42 ++under;
43 return *this;
44 }
45 iterator operator++( int ) {
46 iterator x( *this );
47 ++under;
48 return x;
49 }
50 };
51
52 map_keys( map_t& x ) : x_( x ) {}
53 virtual inline ~map_keys() = default;
54
55 iterator begin() { return iterator( x_.begin() ); }
56 iterator end() { return iterator( x_.end() ); }
57 unsigned int size() const { return x_.size(); }
58
59 map_t& x_;
60};
61
68template <class Mapclass>
69struct map_values {
70 using map_t = Mapclass;
71
72 struct iterator {
73 using realiterator_t = typename std::conditional<std::is_const<map_t>::value,
74 typename map_t::const_iterator,
75 typename map_t::iterator>::type;
76 using value_t =
79 typename map_t::mapped_type>::type;
80 realiterator_t under;
81
82 iterator( realiterator_t x ) : under( x ) {}
83
84 auto operator*() -> typename std::add_lvalue_reference<value_t>::type {
85 return under->second;
86 }
87 auto operator->() -> typename std::add_pointer<value_t>::type { return &under->second; }
88
89 bool operator!=( const iterator& o ) const { return under != o.under; }
90
91 iterator& operator++() {
92 ++under;
93 return *this;
94 }
95 iterator operator++( int ) {
96 iterator x( *this );
97 ++under;
98 return x;
99 }
100 };
101
102 map_values( map_t& x ) : x_( x ) {}
103
104 iterator begin() { return iterator( x_.begin() ); }
105 iterator end() { return iterator( x_.end() ); }
106 unsigned int size() const { return x_.size(); }
107
108 map_t& x_;
109};
110} // namespace Utils
111} // namespace Core
112} // namespace Ra
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3
Generate a range to iterate over the keys of a map.
Generate a range to iterate over the values of a map.