Changeset 108f3cdb for src/Common
- Timestamp:
- Sep 12, 2017, 10:45:01 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 93389c1
- Parents:
- 1395748
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r1395748 r108f3cdb 370 370 } 371 371 372 // ----------------------------------------------------------------------------- 373 // Helper struct and function to support 374 // for ( val : lazy_map( container1, f ) ) {} 375 // syntax to have a for each that iterates a container, mapping each element by applying f 376 template< typename T, typename Func > 377 struct lambda_iterate_t { 378 T & ref; 379 Func f; 380 381 struct iterator { 382 typedef decltype(begin(ref)) Iter; 383 Iter it; 384 Func f; 385 iterator( Iter it, Func f ) : it(it), f(f) {} 386 iterator & operator++() { 387 ++it; return *this; 388 } 389 bool operator!=( const iterator &other ) const { return it != other.it; } 390 auto operator*() const -> decltype(f(*it)) { return f(*it); } 391 }; 392 393 lambda_iterate_t( T & ref, Func f ) : ref(ref), f(f) {} 394 395 auto begin() const -> decltype(iterator(std::begin(ref), f)) { return iterator(std::begin(ref), f); } 396 auto end() const -> decltype(iterator(std::end(ref), f)) { return iterator(std::end(ref), f); } 397 }; 398 399 template< typename... Args > 400 lambda_iterate_t<Args...> lazy_map( Args &&... args ) { 401 return lambda_iterate_t<Args...>(std::forward<Args>( args )...); 402 } 403 404 405 372 406 // Local Variables: // 373 407 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.