Changeset 50377a4 for src/Common
- Timestamp:
- Oct 2, 2017, 4:39:42 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- bf4b4cf
- Parents:
- a8555c5
- Location:
- src/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Indenter.h
ra8555c5 r50377a4 18 18 19 19 struct Indenter { 20 Indenter( unsigned int amt = 2 ) : amt( amt ) {} 21 unsigned int amt = 2; // amount 1 level increases indent by (i.e. how much to increase by in operator++) 22 unsigned int indent = 0; 20 static unsigned tabsize; 21 22 Indenter( unsigned int amt = tabsize, unsigned int indent = 0 ) : amt( amt ), indent( indent ) {} 23 unsigned int amt; // amount 1 level increases indent by (i.e. how much to increase by in operator++) 24 unsigned int indent; 23 25 24 26 Indenter & operator+=(int nlevels) { indent += amt*nlevels; return *this; } … … 30 32 }; 31 33 32 inline std::ostream & operator<<( std::ostream & out, Indenter & indent ) {34 inline std::ostream & operator<<( std::ostream & out, const Indenter & indent ) { 33 35 return out << std::string(indent.indent, ' '); 34 36 } -
src/Common/utility.h
ra8555c5 r50377a4 28 28 #include <cassert> 29 29 30 #include "Common/Indenter.h" 31 30 32 template< typename T > 31 33 static inline T * maybeClone( const T *orig ) { … … 75 77 76 78 template< typename Container > 77 void printAll( const Container &container, std::ostream &os, int indent = 0) {79 void printAll( const Container &container, std::ostream &os, Indenter indent = {} ) { 78 80 for ( typename Container::const_iterator i = container.begin(); i != container.end(); ++i ) { 79 81 if ( *i ) { 80 os << std::string( indent, ' ' );81 (*i)->print( os, indent + 2);82 os << indent; 83 (*i)->print( os, indent ); 82 84 // need an endl after each element because it's not easy to know when each individual item should end 83 85 os << std::endl; … … 351 353 template< typename T1, typename T2 > 352 354 struct group_iterate_t { 355 private: 356 std::tuple<T1, T2> args; 357 public: 353 358 group_iterate_t( bool skipBoundsCheck, const T1 & v1, const T2 & v2 ) : args(v1, v2) { 354 359 assertf(skipBoundsCheck || v1.size() == v2.size(), "group iteration requires containers of the same size: <%zd, %zd>.", v1.size(), v2.size()); 355 360 }; 356 361 362 typedef std::tuple<decltype(*std::get<0>(args).begin()), decltype(*std::get<1>(args).begin())> value_type; 363 typedef decltype(std::get<0>(args).begin()) T1Iter; 364 typedef decltype(std::get<1>(args).begin()) T2Iter; 365 357 366 struct iterator { 358 typedef typename std::remove_reference<T1>::type T1val;359 typedef typename std::remove_reference<T2>::type T2val;360 typedef std::tuple<typename T1val::value_type &, typename T2val::value_type &> value_type;361 typedef typename T1val::iterator T1Iter;362 typedef typename T2val::iterator T2Iter;363 367 typedef std::tuple<T1Iter, T2Iter> IterTuple; 364 368 IterTuple it; … … 370 374 value_type operator*() const { return std::tie( *std::get<0>(it), *std::get<1>(it) ); } 371 375 }; 376 372 377 iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); } 373 378 iterator end() { return iterator( std::get<0>(args).end(), std::get<1>(args).end() ); } 374 375 private:376 std::tuple<T1, T2> args;377 379 }; 378 380
Note: See TracChangeset
for help on using the changeset viewer.