Changeset 7491f97
- Timestamp:
- Nov 14, 2022, 10:57:02 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 19a8c40
- Parents:
- 71806e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r71806e0 r7491f97 461 461 Iterables iterables; 462 462 463 // Getting the iterator and value types this way preserves const. 463 464 template<size_t I> using Iter = decltype(std::get<I>(iterables).begin()); 464 465 template<size_t I> using Data = decltype(*std::get<I>(iterables).begin()); 465 466 template<typename> struct base_iterator; 466 467 467 template<std::size_t... Is> 468 struct base_iterator<std::integer_sequence<std::size_t, Is...>> { 469 using value_type = std::tuple< Data<Is>... >; 470 std::tuple<Iter<Is>...> iterators; 471 472 base_iterator( Iter<Is>... is ) : iterators( is... ) {} 468 // This inner template puts the sequence of `0, 1, ... sizeof...(Args)-1` 469 // into a pack. These are the indexes into the tuples, so unpacking can 470 // go over each element of the tuple. 471 // The std::integer_sequence is just used to build that sequence. 472 // A library reference will probably explain it better than I can. 473 template<std::size_t... Indices> 474 struct base_iterator<std::integer_sequence<std::size_t, Indices...>> { 475 using value_type = std::tuple< Data<Indices>... >; 476 std::tuple<Iter<Indices>...> iterators; 477 478 base_iterator( Iter<Indices>... is ) : iterators( is... ) {} 473 479 base_iterator operator++() { 474 return base_iterator( ++std::get<I s>( iterators )... );480 return base_iterator( ++std::get<Indices>( iterators )... ); 475 481 } 476 482 bool operator!=( const base_iterator& other ) const { … … 478 484 } 479 485 value_type operator*() const { 480 return std::tie( *std::get<I s>( iterators )... );486 return std::tie( *std::get<Indices>( iterators )... ); 481 487 } 482 488 483 489 static base_iterator make_begin( Iterables & data ) { 484 return base_iterator( std::get<I s>( data ).begin()... );490 return base_iterator( std::get<Indices>( data ).begin()... ); 485 491 } 486 492 static base_iterator make_end( Iterables & data ) { 487 return base_iterator( std::get<I s>( data ).end()... );493 return base_iterator( std::get<Indices>( data ).end()... ); 488 494 } 489 495 };
Note: See TracChangeset
for help on using the changeset viewer.