summaryrefslogtreecommitdiff
path: root/project2/common/safeMapFind.h
blob: b27caf32ba25900db8667ba2d3a57504056bf215 (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
#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;
}

#endif