Changes in src/Common/utility.h [fbecee5:5cbacf1]
- File:
-
- 1 edited
-
src/Common/utility.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
rfbecee5 r5cbacf1 26 26 #include <string> 27 27 #include <type_traits> 28 #include <utility>29 28 30 29 #include <cassert> … … 463 462 std::pair<long long int, bool> eval(Expression * expr); 464 463 465 // -----------------------------------------------------------------------------466 /// Reorders the input range in-place so that the minimal-value elements according to the467 /// comparator are in front;468 /// returns the iterator after the last minimal-value element.469 template<typename Iter, typename Compare>470 Iter sort_mins( Iter begin, Iter end, Compare& lt ) {471 if ( begin == end ) return end;472 473 Iter min_pos = begin;474 for ( Iter i = begin + 1; i != end; ++i ) {475 if ( lt( *i, *min_pos ) ) {476 // new minimum cost; swap into first position477 min_pos = begin;478 std::iter_swap( min_pos, i );479 } else if ( ! lt( *min_pos, *i ) ) {480 // duplicate minimum cost; swap into next minimum position481 ++min_pos;482 std::iter_swap( min_pos, i );483 }484 }485 return ++min_pos;486 }487 488 template<typename Iter, typename Compare>489 inline Iter sort_mins( Iter begin, Iter end, Compare&& lt ) {490 return sort_mins( begin, end, lt );491 }492 493 /// sort_mins defaulted to use std::less494 template<typename Iter>495 inline Iter sort_mins( Iter begin, Iter end ) {496 return sort_mins( begin, end, std::less<typename std::iterator_traits<Iter>::value_type>{} );497 }498 499 464 // Local Variables: // 500 465 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.