Changeset 0531b5d for src/GenPoly/ScopedMap.h
- Timestamp:
- Mar 9, 2016, 3:11:25 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 89173242
- Parents:
- d1caa6c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/ScopedMap.h
rd1caa6c r0531b5d 17 17 #define _SCOPEDMAP_H 18 18 19 #include <cassert> 19 20 #include <iterator> 20 21 #include <map> … … 164 165 void endScope() { 165 166 scopes.pop_back(); 167 assert( ! scopes.empty() ); 166 168 } 167 169 … … 188 190 return end(); 189 191 } 190 const_iterator find( const Key &key ) const { return const_iterator( find( key ) ); } 192 const_iterator find( const Key &key ) const { 193 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) ); 194 } 191 195 192 196 /// Finds the given key in the outermost scope inside the given scope where it occurs … … 200 204 return end(); 201 205 } 202 const_iterator findNext( const_iterator &it, const Key &key ) const { return const_iterator( findNext( it, key ) ); } 206 const_iterator findNext( const_iterator &it, const Key &key ) const { 207 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findNext( it, key ) ); 208 } 203 209 204 210 /// Inserts the given key-value pair into the outermost scope … … 208 214 } 209 215 std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); } 210 216 217 Value& operator[] ( const Key &key ) { 218 iterator slot = find( key ); 219 if ( slot != end() ) return slot->second; 220 return insert( key, Value() ).first->second; 221 } 211 222 }; 212 223 } // namespace GenPoly
Note: See TracChangeset
for help on using the changeset viewer.