blob: a5786bc7409f1699e1658adf375f721276966cf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#ifndef SAFEMAPFIND_H
#define SAFEMAPFIND_H
template <class Ex, class Map>
typename Map::const_iterator
safeMapFind(const Map & map, const typename Map::key_type & key)
{
typename Map::const_iterator i = map.find(key);
if (i == map.end()) {
throw Ex(key);
}
return i;
}
template <class Map>
typename Map::mapped_type
defaultMapFind(const Map & map, const typename Map::key_type & key, const typename Map::mapped_type & def = typename Map::mapped_type())
{
typename Map::const_iterator i = map.find(key);
if (i == map.end()) {
return def;
}
return i->second;
}
template <class Ex, class Map>
const typename Map::mapped_type &
safeMapLookup(const Map & map, const typename Map::key_type & key)
{
typename Map::const_iterator i = map.find(key);
if (i == map.end()) {
throw Ex(key);
}
return i->second;
}
template <class Cont>
bool
containerContains(const Cont & c, const typename Cont::value_type & v)
{
return (std::find(c.begin(), c.end(), v) != c.end());
}
#endif
|