From e4a4051b6f21177969c82796805b03c42e5063e4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 28 Aug 2015 01:33:39 +0100 Subject: Add map utilities --- project2/lib/safeMapFind.h | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 project2/lib/safeMapFind.h 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 -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 -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 -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 -bool -containerContains(const Cont & c, const typename Cont::value_type & v) -{ - return (std::find(c.begin(), c.end(), v) != c.end()); -} - -#endif - -- cgit v1.2.3