27template <
typename Map,
typename Key>
28typename Map::mapped_type get(
const Map &m,
const Key &key) {
29 auto it = m.find(key);
30 return it != m.end() ? it->second :
typename Map::mapped_type{};
32template <
class Map,
typename Key,
typename Value>
33typename Map::mapped_type get(
const Map &m,
const Key &key,
Value &&def) {
34 using M =
typename Map::mapped_type;
35 auto it = m.find(key);
36 return it != m.end() ? it->second :
static_cast<M
>(std::forward<Value>(def));
41template <
typename Map,
typename Key>
42const typename Map::mapped_type *getref(
const Map &m,
const Key &key) {
43 auto it = m.find(key);
44 return it != m.end() ? &it->second :
nullptr;
47template <
typename Map,
typename Key>
48typename Map::mapped_type *getref(Map &m,
const Key &key) {
49 auto it = m.find(key);
50 return it != m.end() ? &it->second :
nullptr;
55template <
class Map,
typename Key>
56std::optional<typename Map::mapped_type> get_optional(
const Map &m,
const Key &key) {
57 auto it = m.find(key);
58 if (it != m.end())
return std::optional<typename Map::mapped_type>(it->second);
63template <
typename Map,
typename Key>
64typename Map::mapped_type get(
const Map *m,
const Key &key) {
65 return m ? get(*m, key) : typename Map::mapped_type{};
68template <
class Map,
typename Key,
typename Value>
69typename Map::mapped_type get(
const Map *m,
const Key &key,
Value &&def) {
70 return m ? get(*m, key, std::forward(def)) : typename Map::mapped_type{};
73template <
typename Map,
typename Key>
74const typename Map::mapped_type *getref(
const Map *m,
const Key &key) {
75 return m ? getref(*m, key) : nullptr;
78template <
typename Map,
typename Key>
79typename Map::mapped_type *getref(Map *m,
const Key &key) {
80 return m ? getref(*m, key) : nullptr;
84template <
class PairIter>
90 using iterator_category =
typename std::iterator_traits<PairIter>::iterator_category;
91 using value_type =
typename std::iterator_traits<PairIter>::value_type::first_type;
92 using difference_type =
typename std::iterator_traits<PairIter>::difference_type;
93 using pointer =
decltype(&it->first);
94 using reference =
decltype(*&it->first);
96 explicit iterator(PairIter i) : it(i) {}
97 iterator &operator++() {
101 iterator &operator--() {
105 iterator operator++(
int) {
110 iterator operator--(
int) {
115 bool operator==(
const iterator &i)
const {
return it == i.it; }
116 bool operator!=(
const iterator &i)
const {
return it != i.it; }
117 reference operator*()
const {
return it->first; }
118 pointer operator->()
const {
return &it->first; }
123 explicit IterKeys(U &map) : b(map.begin()), e(map.end()) {}
124 IterKeys(PairIter b, PairIter e) : b(b), e(e) {}
125 iterator begin()
const {
return b; }
126 iterator end()
const {
return e; }
135IterKeys<typename Map::const_iterator> Keys(
const Map &m) {
136 return IterKeys<typename Map::const_iterator>(m);
139template <
class PairIter>
140IterKeys<PairIter> Keys(std::pair<PairIter, PairIter> range) {
141 return IterKeys<PairIter>(range.first, range.second);
145template <
class PairIter>
151 using iterator_category =
typename std::iterator_traits<PairIter>::iterator_category;
152 using value_type =
typename std::iterator_traits<PairIter>::value_type::second_type;
153 using difference_type =
typename std::iterator_traits<PairIter>::difference_type;
154 using pointer =
decltype(&it->second);
155 using reference =
decltype(*&it->second);
157 explicit iterator(PairIter i) : it(i) {}
158 iterator &operator++() {
162 iterator &operator--() {
166 iterator operator++(
int) {
171 iterator operator--(
int) {
176 bool operator==(
const iterator &i)
const {
return it == i.it; }
177 bool operator!=(
const iterator &i)
const {
return it != i.it; }
178 reference operator*()
const {
return it->second; }
179 pointer operator->()
const {
return &it->second; }
183 using value_type =
typename std::iterator_traits<PairIter>::value_type::second_type;
186 explicit IterValues(U &map) : b(map.begin()), e(map.end()) {}
187 IterValues(PairIter b, PairIter e) : b(b), e(e) {}
188 iterator begin()
const {
return b; }
189 iterator end()
const {
return e; }
198IterValues<typename Map::const_iterator> Values(
const Map &m) {
199 return IterValues<typename Map::const_iterator>(m);
202template <
class PairIter>
203IterValues<PairIter> Values(std::pair<PairIter, PairIter> range) {
204 return IterValues<PairIter>(range.first, range.second);
211 typename M::key_type key;
213 using MapIt =
decltype(map.begin());
219 using iterator_category = std::forward_iterator_tag;
220 using value_type =
typename M::value_type;
221 using difference_type =
typename std::iterator_traits<MapIt>::difference_type;
222 using pointer =
decltype(&it->second);
223 using reference =
decltype(*&it->second);
225 iterator(
const MapForKey &s, MapIt i) : self(s), it(std::move(i)) {}
226 iterator &operator++() {
227 if (++it != self.map.end() && it->first != self.key) it = self.map.end();
230 iterator operator++(
int) {
235 bool operator==(
const iterator &i)
const {
return it == i.it; }
236 bool operator!=(
const iterator &i)
const {
return it != i.it; }
237 reference operator*()
const {
return it->second; }
238 pointer operator->()
const {
return &it->second; }
242 MapForKey(M &m,
typename M::key_type k) : map(m), key(k) {}
243 iterator begin()
const {
return iterator(*
this, map.find(key)); }
244 iterator end()
const {
return iterator(*
this, map.end()); }
248MapForKey<M> ValuesForKey(M &m,
typename M::key_type k) {
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24