Changeset 7491f97


Ignore:
Timestamp:
Nov 14, 2022, 10:57:02 AM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
19a8c40
Parents:
71806e0
Message:

Renaming and comments in group_iterate_t to help clarity.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r71806e0 r7491f97  
    461461        Iterables iterables;
    462462
     463        // Getting the iterator and value types this way preserves const.
    463464        template<size_t I> using Iter = decltype(std::get<I>(iterables).begin());
    464465        template<size_t I> using Data = decltype(*std::get<I>(iterables).begin());
    465466        template<typename> struct base_iterator;
    466467
    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... ) {}
    473479                base_iterator operator++() {
    474                         return base_iterator( ++std::get<Is>( iterators )... );
     480                        return base_iterator( ++std::get<Indices>( iterators )... );
    475481                }
    476482                bool operator!=( const base_iterator& other ) const {
     
    478484                }
    479485                value_type operator*() const {
    480                         return std::tie( *std::get<Is>( iterators )... );
     486                        return std::tie( *std::get<Indices>( iterators )... );
    481487                }
    482488
    483489                static base_iterator make_begin( Iterables & data ) {
    484                         return base_iterator( std::get<Is>( data ).begin()... );
     490                        return base_iterator( std::get<Indices>( data ).begin()... );
    485491                }
    486492                static base_iterator make_end( Iterables & data ) {
    487                         return base_iterator( std::get<Is>( data ).end()... );
     493                        return base_iterator( std::get<Indices>( data ).end()... );
    488494                }
    489495        };
Note: See TracChangeset for help on using the changeset viewer.