From f3760b0f2828250b4b5fb1a52601fe6b11ff328f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 6 Nov 2015 13:22:16 -0800 Subject: 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 --- 001help.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to '001help.cc') 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::mapped_type& get(T& map, typename T::key_type c assert(iter != map.end()); return iter->second; } -template typename T::mapped_type& get_or_insert(T& map, typename T::key_type const& key) { - return map[key]; -} template 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 bool contains_key(T& map, typename T::key_type const& key) { + return map.find(key) != map.end(); +} +template 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 -- cgit 1.4.1-2-gfad0