Changeset 46f6134 for src/GenPoly
- Timestamp:
- Aug 29, 2016, 12:20:45 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- ad4581b, b542bfb
- Parents:
- 5e644d3e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/ScopedMap.h
r5e644d3e r46f6134 42 42 typedef typename Scope::pointer pointer; 43 43 typedef typename Scope::const_pointer const_pointer; 44 44 45 45 class iterator : public std::iterator< std::bidirectional_iterator_tag, 46 46 value_type > { … … 68 68 } 69 69 70 iterator(scope_list const&_scopes, const wrapped_iterator &_it, size_type _i)70 iterator(scope_list &_scopes, const wrapped_iterator &_it, size_type _i) 71 71 : scopes(&_scopes), it(_it), i(_i) {} 72 72 public: … … 76 76 return *this; 77 77 } 78 78 79 79 reference operator* () { return *it; } 80 80 pointer operator-> () { return it.operator->(); } … … 109 109 110 110 private: 111 scope_list const*scopes;111 scope_list *scopes; 112 112 wrapped_iterator it; 113 113 size_type i; … … 189 189 size_type i; 190 190 }; 191 191 192 192 /// Starts a new scope 193 193 void beginScope() { 194 Scope scope; 195 scopes.push_back(scope); 194 scopes.emplace_back(); 196 195 } 197 196 … … 227 226 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) ); 228 227 } 229 228 230 229 /// Finds the given key in the outermost scope inside the given scope where it occurs 231 230 iterator findNext( const_iterator &it, const Key &key ) { … … 247 246 return std::make_pair( iterator(scopes, res.first, scopes.size()-1), res.second ); 248 247 } 248 249 std::pair< iterator, bool > insert( value_type &&value ) { 250 std::pair< typename Scope::iterator, bool > res = scopes.back().insert( std::move( value ) ); 251 return std::make_pair( iterator(scopes, std::move( res.first ), scopes.size()-1), std::move( res.second ) ); 252 } 253 249 254 std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); } 255 std::pair< iterator, bool > insert( const Key &key, Value &&value ) { return insert( std::make_pair( key, std::move( value ) ) ); } 250 256 251 257 Value& operator[] ( const Key &key ) { … … 254 260 return insert( key, Value() ).first->second; 255 261 } 262 263 iterator erase( iterator pos ) { 264 Scope& scope = (*pos.scopes) [ pos.i ]; 265 const typename iterator::wrapped_iterator& new_it = scope.erase( pos.it ); 266 iterator it( *pos.scopes, new_it, pos.i ); 267 return it.next_valid(); 268 } 269 270 size_type count( const Key &key ) const { 271 size_type c = 0; 272 auto it = find( key ); 273 auto end = cend(); 274 275 while(it != end) { 276 c++; 277 it = findNext(it, key); 278 } 279 280 return c; 281 } 282 256 283 }; 257 284 } // namespace GenPoly
Note:
See TracChangeset
for help on using the changeset viewer.