Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r21f0aa8 r6b0b624  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 11:38:00 2017
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul 21 22:19:13 2017
     13// Update Count     : 33
    1414//
    1515
     
    2424#include <sstream>
    2525#include <string>
    26 #include <type_traits>
    2726
    2827#include <cassert>
    29 
    3028template< typename T >
    3129static inline T * maybeClone( const T *orig ) {
     
    306304// for ( val : group_iterate( container1, container2, ... ) ) {}
    307305// syntax to have a for each that iterates multiple containers of the same length
    308 // TODO: update to use variadic arguments
     306// TODO: update to use variadic arguments, perfect forwarding
    309307
    310308template< typename T1, typename T2 >
     
    315313
    316314        struct iterator {
    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;
     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;
    322318                typedef std::tuple<T1Iter, T2Iter> IterTuple;
    323319                IterTuple it;
     
    327323                }
    328324                bool operator!=( const iterator &other ) const { return it != other.it; }
    329                 value_type operator*() const { return std::tie( *std::get<0>(it), *std::get<1>(it) ); }
     325                value_type operator*() const { return std::make_tuple( *std::get<0>(it), *std::get<1>(it) ); }
    330326        };
    331327        iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); }
     
    337333
    338334template< typename... Args >
    339 group_iterate_t<Args...> group_iterate( Args &&... args ) {
    340         return group_iterate_t<Args...>(std::forward<Args>( args )...);
     335group_iterate_t<Args...> group_iterate( const Args &... args ) {
     336        return group_iterate_t<Args...>(args...);
     337}
     338
     339struct 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
     373inline std::string to_string( const CodeLocation& location ) {
     374        return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
    341375}
    342376
Note: See TracChangeset for help on using the changeset viewer.