Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r77d2432 rb6d7f44  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 24 14:28:19 2019
    13 // Update Count     : 41
     12// Last Modified On : Sun May  6 22:24:16 2018
     13// Update Count     : 40
    1414//
    1515
    1616#pragma once
    1717
    18 #include <cassert>
    1918#include <cctype>
    2019#include <algorithm>
     
    2726#include <string>
    2827#include <type_traits>
    29 #include <utility>
    30 #include <vector>
     28
     29#include <cassert>
    3130
    3231#include "Common/Indenter.h"
    33 
    34 class Expression;
    35 
    36 /// bring std::move into global scope
    37 using std::move;
    38 
    39 /// partner to move that copies any copyable type
    40 template<typename T>
    41 T copy( const T & x ) { return x; }
    4232
    4333template< typename T >
     
    8171
    8272template< typename Container >
    83 void deleteAll( const Container &container ) {
    84         for ( const auto &i : container ) {
    85                 delete i;
     73void deleteAll( Container &container ) {
     74        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
     75                delete *i;
    8676        } // for
    8777}
     
    152142                return ret;
    153143        } // switch
    154 }
    155 
    156 /// Splice src onto the end of dst, clearing src
    157 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 src
    165 template< typename T >
    166 void spliceBegin( std::vector< T > & dst, std::vector< T > & src ) {
    167         splice( src, dst );
    168         dst.swap( src );
    169144}
    170145
     
    481456} // ilog2
    482457
    483 // -----------------------------------------------------------------------------
    484 /// evaluates expr as a long long int. If second is false, expr could not be evaluated
    485 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 the
    495 /// 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 position
    505                         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 position
    509                         ++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::less
    522 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 }
    526458
    527459// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.