Ignore:
Timestamp:
Jan 24, 2017, 3:56:33 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
ad6343e
Parents:
0bfaf80
Message:

propagate sized status through trait instances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r0bfaf80 r4a9ccc3  
    252252
    253253template< typename T >
    254 struct reverseIterate_t {
     254struct reverse_iterate_t {
    255255        T& ref;
    256256
    257         reverseIterate_t( T & ref ) : ref(ref) {}
     257        reverse_iterate_t( T & ref ) : ref(ref) {}
    258258
    259259        typedef typename T::reverse_iterator iterator;
     
    263263
    264264template< typename T >
    265 reverseIterate_t< T > reverseIterate( T & ref ) {
    266         return reverseIterate_t< T >( ref );
    267 }
    268 
     265reverse_iterate_t< T > reverseIterate( T & ref ) {
     266        return reverse_iterate_t< T >( ref );
     267}
     268
     269// -----------------------------------------------------------------------------
     270// Helper struct and function to support
     271// for ( val : group_iterate( container1, container2, ... ) ) {}
     272// syntax to have a for each that iterates multiple containers of the same length
     273// TODO: update to use variadic arguments
     274
     275template< typename T1, typename T2 >
     276struct group_iterate_t {
     277        group_iterate_t( const T1 & v1, const T2 & v2 ) : args(v1, v2) {
     278                assertf(v1.size() == v2.size(), "group iteration requires containers of the same size.");
     279        };
     280
     281        struct iterator {
     282                typedef std::tuple<typename T1::value_type, typename T2::value_type> value_type;
     283                typedef typename T1::iterator T1Iter;
     284                typedef typename T2::iterator T2Iter;
     285                typedef std::tuple<T1Iter, T2Iter> IterTuple;
     286                IterTuple it;
     287                iterator( T1Iter i1, T2Iter i2 ) : it( i1, i2 ) {}
     288                iterator operator++() {
     289                        return iterator( ++std::get<0>(it), ++std::get<1>(it) );
     290                }
     291                bool operator!=( const iterator &other ) const { return it != other.it; }
     292                value_type operator*() const { return std::make_tuple( *std::get<0>(it), *std::get<1>(it) ); }
     293        };
     294        iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); }
     295        iterator end() { return iterator( std::get<0>(args).end(), std::get<1>(args).end() ); }
     296
     297private:
     298        std::tuple<T1, T2> args;
     299};
     300
     301template< typename... Args >
     302group_iterate_t<Args...> group_iterate( const Args &... args ) {
     303        return group_iterate_t<Args...>(args...);
     304}
    269305#endif // _UTILITY_H
    270306
Note: See TracChangeset for help on using the changeset viewer.