Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Candidate.hpp

    r99d4584 r432ce7a  
    3030        /// A list of unresolved assertions
    3131        using AssertionList = std::vector<AssertionSet::value_type>;
     32
     33        /// Convenience to merge AssertionList into AssertionSet
     34        static inline void mergeAssertionSet( AssertionSet & dst, const AssertionList & src ) {
     35                for ( const auto & s : src ) { dst.emplace( s ); }
     36        }
    3237}
    3338
     
    4247        ast::OpenVarSet open;      ///< Open variables for environment
    4348        ast::AssertionList need;   ///< Assertions which need to be resolved
     49
     50        Candidate() : expr(), cost( Cost::zero ), cvtCost( Cost::zero ), env(), open(), need() {}
     51       
     52        Candidate( const ast::Expr * x, const ast::TypeEnvironment & e )
     53        : expr( x ), cost( Cost::zero ), cvtCost( Cost::zero ), env( e ), open(), need() {}
     54
     55        Candidate( const Candidate & o, const ast::Expr * x )
     56        : expr( x ), cost( o.cost ), cvtCost( Cost::zero ), env( o.env ), open( o.open ),
     57          need( o.need ) {}
     58       
     59        Candidate(
     60                const ast::Expr * x, ast::TypeEnvironment && e, ast::OpenVarSet && o,
     61                ast::AssertionSet && n, const Cost & c )
     62        : expr( x ), cost( c ), cvtCost( Cost::zero ), env( std::move( e ) ), open( std::move( o ) ),
     63          need( n.begin(), n.end() ) {}
    4464};
    4565
     
    4969/// List of candidates
    5070using CandidateList = std::vector< CandidateRef >;
     71
     72/// Splice src after dst, clearing src
     73static inline void splice( CandidateList & dst, CandidateList & src ) {
     74        dst.reserve( dst.size() + src.size() );
     75        for ( CandidateRef & r : src ) { dst.emplace_back( std::move( r ) ); }
     76        src.clear();
     77}
     78
     79/// Splice src before dst
     80static inline void spliceBegin( CandidateList & dst, CandidateList & src ) {
     81        splice( src, dst );
     82        dst.swap( src );
     83}
     84
     85/// Sum the cost of a list of candidates
     86static inline Cost sumCost( const CandidateList & candidates ) {
     87        Cost total = Cost::zero;
     88        for ( const CandidateRef & r : candidates ) { total += r->cost; }
     89        return total;
     90}
     91
     92/// Holdover behaviour from old `findMinCost` -- xxx -- can maybe be eliminated?
     93static inline void promoteCvtCost( CandidateList & candidates ) {
     94        for ( CandidateRef & r : candidates ) {
     95                r->cost = r->cvtCost;
     96        }
     97}
    5198
    5299void print( std::ostream & os, const Candidate & cand, Indenter indent = {} );
Note: See TracChangeset for help on using the changeset viewer.