Changes in src/Common/utility.h [77d2432:b6d7f44]
- File:
-
- 1 edited
-
src/Common/utility.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r77d2432 rb6d7f44 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 24 14:28:19 201913 // Update Count : 4 112 // Last Modified On : Sun May 6 22:24:16 2018 13 // Update Count : 40 14 14 // 15 15 16 16 #pragma once 17 17 18 #include <cassert>19 18 #include <cctype> 20 19 #include <algorithm> … … 27 26 #include <string> 28 27 #include <type_traits> 29 #include <utility> 30 #include < vector>28 29 #include <cassert> 31 30 32 31 #include "Common/Indenter.h" 33 34 class Expression;35 36 /// bring std::move into global scope37 using std::move;38 39 /// partner to move that copies any copyable type40 template<typename T>41 T copy( const T & x ) { return x; }42 32 43 33 template< typename T > … … 81 71 82 72 template< typename Container > 83 void deleteAll( constContainer &container ) {84 for ( const auto &i : container) {85 delete i;73 void deleteAll( Container &container ) { 74 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 75 delete *i; 86 76 } // for 87 77 } … … 152 142 return ret; 153 143 } // switch 154 }155 156 /// Splice src onto the end of dst, clearing src157 template< typename T >158 void splice( std::vector< T > & dst, std::vector< T > & src ) {159 dst.reserve( dst.size() + src.size() );160 for ( T & x : src ) { dst.emplace_back( std::move( x ) ); }161 src.clear();162 }163 164 /// Splice src onto the begining of dst, clearing src165 template< typename T >166 void spliceBegin( std::vector< T > & dst, std::vector< T > & src ) {167 splice( src, dst );168 dst.swap( src );169 144 } 170 145 … … 481 456 } // ilog2 482 457 483 // -----------------------------------------------------------------------------484 /// evaluates expr as a long long int. If second is false, expr could not be evaluated485 std::pair<long long int, bool> eval(const Expression * expr);486 487 namespace ast {488 class Expr;489 }490 491 std::pair<long long int, bool> eval(const ast::Expr * expr);492 493 // -----------------------------------------------------------------------------494 /// Reorders the input range in-place so that the minimal-value elements according to the495 /// comparator are in front;496 /// returns the iterator after the last minimal-value element.497 template<typename Iter, typename Compare>498 Iter sort_mins( Iter begin, Iter end, Compare& lt ) {499 if ( begin == end ) return end;500 501 Iter min_pos = begin;502 for ( Iter i = begin + 1; i != end; ++i ) {503 if ( lt( *i, *min_pos ) ) {504 // new minimum cost; swap into first position505 min_pos = begin;506 std::iter_swap( min_pos, i );507 } else if ( ! lt( *min_pos, *i ) ) {508 // duplicate minimum cost; swap into next minimum position509 ++min_pos;510 std::iter_swap( min_pos, i );511 }512 }513 return ++min_pos;514 }515 516 template<typename Iter, typename Compare>517 inline Iter sort_mins( Iter begin, Iter end, Compare&& lt ) {518 return sort_mins( begin, end, lt );519 }520 521 /// sort_mins defaulted to use std::less522 template<typename Iter>523 inline Iter sort_mins( Iter begin, Iter end ) {524 return sort_mins( begin, end, std::less<typename std::iterator_traits<Iter>::value_type>{} );525 }526 458 527 459 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.