Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r6b0b624 r21f0aa8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:19:13 2017
    13 // Update Count     : 33
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 17 11:38:00 2017
     13// Update Count     : 34
    1414//
    1515
     
    2424#include <sstream>
    2525#include <string>
     26#include <type_traits>
    2627
    2728#include <cassert>
     29
    2830template< typename T >
    2931static inline T * maybeClone( const T *orig ) {
     
    304306// for ( val : group_iterate( container1, container2, ... ) ) {}
    305307// syntax to have a for each that iterates multiple containers of the same length
    306 // TODO: update to use variadic arguments, perfect forwarding
     308// TODO: update to use variadic arguments
    307309
    308310template< typename T1, typename T2 >
     
    313315
    314316        struct iterator {
    315                 typedef std::tuple<typename T1::value_type, typename T2::value_type> value_type;
    316                 typedef typename T1::iterator T1Iter;
    317                 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;
    318322                typedef std::tuple<T1Iter, T2Iter> IterTuple;
    319323                IterTuple it;
     
    323327                }
    324328                bool operator!=( const iterator &other ) const { return it != other.it; }
    325                 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) ); }
    326330        };
    327331        iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); }
     
    333337
    334338template< typename... Args >
    335 group_iterate_t<Args...> group_iterate( const Args &... args ) {
    336         return group_iterate_t<Args...>(args...);
    337 }
    338 
    339 struct CodeLocation {
    340         int linenumber;
    341         std::string filename;
    342 
    343         /// Create a new unset CodeLocation.
    344         CodeLocation()
    345                 : linenumber( -1 )
    346                 , filename("")
    347         {}
    348 
    349         /// Create a new CodeLocation with the given values.
    350         CodeLocation( const char* filename, int lineno )
    351                 : linenumber( lineno )
    352                 , filename(filename ? filename : "")
    353         {}
    354 
    355         CodeLocation( const CodeLocation& rhs ) = default;
    356 
    357         bool isSet () const {
    358                 return -1 != linenumber;
    359         }
    360 
    361         bool isUnset () const {
    362                 return !isSet();
    363         }
    364 
    365         void unset () {
    366                 linenumber = -1;
    367                 filename = "";
    368         }
    369 
    370         // Use field access for set.
    371 };
    372 
    373 inline std::string to_string( const CodeLocation& location ) {
    374         return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
     339group_iterate_t<Args...> group_iterate( Args &&... args ) {
     340        return group_iterate_t<Args...>(std::forward<Args>( args )...);
    375341}
    376342
Note: See TracChangeset for help on using the changeset viewer.