diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-06 13:22:16 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-06 13:22:30 -0800 |
commit | f3760b0f2828250b4b5fb1a52601fe6b11ff328f (patch) | |
tree | 69ec57c652ff823e92146281ba656e3eaba57eb7 /001help.cc | |
parent | 12f304a333ecee6326a8111e0d8e1c494ee92087 (diff) | |
download | mu-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.cc | 11 |
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> |