Changeset 55a68c3


Ignore:
Timestamp:
Jul 13, 2017, 3:56:04 PM (4 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:
3d4b23f
Parents:
a5de33e
Message:

Update group_iterate with perfect forwarding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    ra5de33e r55a68c3  
    2525#include <sstream>
    2626#include <string>
     27#include <type_traits>
    2728
    2829#include <cassert>
     
    305306// for ( val : group_iterate( container1, container2, ... ) ) {}
    306307// syntax to have a for each that iterates multiple containers of the same length
    307 // TODO: update to use variadic arguments, perfect forwarding
     308// TODO: update to use variadic arguments
    308309
    309310template< typename T1, typename T2 >
     
    314315
    315316        struct iterator {
    316                 typedef std::tuple<typename T1::value_type, typename T2::value_type> value_type;
    317                 typedef typename T1::iterator T1Iter;
    318                 typedef typename T2::iterator T2Iter;
     317                typedef typename std::remove_reference<T1>::type T1val;
     318                typedef typename std::remove_reference<T2>::type T2val;
     319                typedef std::tuple<typename T1val::value_type &, typename T2val::value_type &> value_type;
     320                typedef typename T1val::iterator T1Iter;
     321                typedef typename T2val::iterator T2Iter;
    319322                typedef std::tuple<T1Iter, T2Iter> IterTuple;
    320323                IterTuple it;
     
    324327                }
    325328                bool operator!=( const iterator &other ) const { return it != other.it; }
    326                 value_type operator*() const { return std::make_tuple( *std::get<0>(it), *std::get<1>(it) ); }
     329                value_type operator*() const { return std::tie( *std::get<0>(it), *std::get<1>(it) ); }
    327330        };
    328331        iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); }
     
    334337
    335338template< typename... Args >
    336 group_iterate_t<Args...> group_iterate( const Args &... args ) {
    337         return group_iterate_t<Args...>(args...);
     339group_iterate_t<Args...> group_iterate( Args &&... args ) {
     340        return group_iterate_t<Args...>(std::forward<Args>( args )...);
    338341}
    339342
Note: See TracChangeset for help on using the changeset viewer.