diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-08-28 01:33:39 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-08-28 01:33:39 +0100 |
commit | e4a4051b6f21177969c82796805b03c42e5063e4 (patch) | |
tree | 7e5c7172d9ed90bbcba2d22b016f39ee56d49914 | |
parent | Move more stuff from common to basics (diff) | |
download | project2-e4a4051b6f21177969c82796805b03c42e5063e4.tar.bz2 project2-e4a4051b6f21177969c82796805b03c42e5063e4.tar.xz project2-e4a4051b6f21177969c82796805b03c42e5063e4.zip |
Add map utilities
-rw-r--r-- | project2/lib/safeMapFind.h | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/project2/lib/safeMapFind.h b/project2/lib/safeMapFind.h deleted file mode 100644 index a5786bc..0000000 --- a/project2/lib/safeMapFind.h +++ /dev/null @@ -1,45 +0,0 @@ -#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 - |