Ignore:
Timestamp:
Jan 14, 2019, 3:38:28 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer
Children:
fd73248
Parents:
07ec1a2 (diff), 52ffa30 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r07ec1a2 r276a55b2  
    2626#include <string>
    2727#include <type_traits>
     28#include <utility>
    2829
    2930#include <cassert>
     
    462463std::pair<long long int, bool> eval(Expression * expr);
    463464
     465// -----------------------------------------------------------------------------
     466/// Reorders the input range in-place so that the minimal-value elements according to the
     467/// comparator are in front;
     468/// returns the iterator after the last minimal-value element.
     469template<typename Iter, typename Compare>
     470Iter 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 position
     477                        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 position
     481                        ++min_pos;
     482                        std::iter_swap( min_pos, i );
     483                }
     484        }
     485        return ++min_pos;
     486}
     487
     488template<typename Iter, typename Compare>
     489inline 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::less
     494template<typename Iter>
     495inline Iter sort_mins( Iter begin, Iter end ) {
     496        return sort_mins( begin, end, std::less<typename std::iterator_traits<Iter>::value_type>{} );
     497}
     498
    464499// Local Variables: //
    465500// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.