about summary refs log tree commit diff stats
path: root/001help.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-06 13:22:16 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-06 13:22:30 -0800
commitf3760b0f2828250b4b5fb1a52601fe6b11ff328f (patch)
tree69ec57c652ff823e92146281ba656e3eaba57eb7 /001help.cc
parent12f304a333ecee6326a8111e0d8e1c494ee92087 (diff)
downloadmu-f3760b0f2828250b4b5fb1a52601fe6b11ff328f.tar.gz
2379 - further improvements to map operations
Commands run:

  $ sed -i 's/\([^. (]*\)\.find(\([^)]*\)) != [^.]*\.end()/contains_key(\1, \2)/g' 0[^0]*cc
  $ sed -i 's/\([^. (]*\)\.find(\([^)]*\)) == [^.]*\.end()/!contains_key(\1, \2)/g' 0[^0]*cc
Diffstat (limited to '001help.cc')
-rw-r--r--001help.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/001help.cc b/001help.cc
index 3ed85e12..e42dc6a7 100644
--- a/001help.cc
+++ b/001help.cc
@@ -96,13 +96,18 @@ template<typename T> typename T::mapped_type& get(T& map, typename T::key_type c
   assert(iter != map.end());
   return iter->second;
 }
-template<typename T> typename T::mapped_type& get_or_insert(T& map, typename T::key_type const& key) {
-  return map[key];
-}
 template<typename T> typename T::mapped_type const& put(T& map, typename T::key_type const& key, typename T::mapped_type const& value) {
   map[key] = value;
   return map[key];
 }
+template<typename T> bool contains_key(T& map, typename T::key_type const& key) {
+  return map.find(key) != map.end();
+}
+template<typename T> typename T::mapped_type& get_or_insert(T& map, typename T::key_type const& key) {
+  return map[key];
+}
+//: The contract: any container that relies on get_or_insert should never call
+//: contains_key.
 
 :(before "End Includes")
 #include<assert.h>