Changeset 4563a95


Ignore:
Timestamp:
Sep 8, 2016, 4:50:15 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
7d05e7e, 850fda6, d1969a6, f5e81d1
Parents:
ee1635c8 (diff), 119745e (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:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    ree1635c8 r4563a95  
    1818
    1919#include <cctype>
     20#include <algorithm>
    2021#include <iostream>
    2122#include <iterator>
     
    111112                return tmp;
    112113        } // if
    113 }
    114 
    115 template< class T, typename ResultType, ResultType( T::* memfunc )() >
    116 ResultType dispatch( T *pT ) {
    117         return (pT->*memfunc)();
    118114}
    119115
     
    162158}
    163159
    164 template< class Constructed, typename Arg >
    165 Constructed *ctor( Arg arg ) {
    166         Constructed *c = new Constructed( arg );
    167         return c;
    168 }
    169 
    170 template< class Constructed, typename Arg >
    171 Constructed ctor_noptr( Arg arg ) {
    172         return Constructed( arg );
    173 }
    174 
    175160template< typename T >
    176161void replace( std::list< T > &org, typename std::list< T >::iterator pos, std::list< T > &with ) {
     
    185170}
    186171
    187 template< typename T1, typename T2 >
    188 T2 *cast_ptr( T1 *from ) {
    189         return dynamic_cast< T2 * >( from );
    190 }
    191 
    192 template< class Exception, typename Arg >
    193 void inline assert_throw( bool pred, Arg arg ) {
    194         if (pred) throw Exception( arg );
    195 }
    196 
    197 template< typename T >
    198 struct is_null_pointer {
    199         bool operator()( const T *ptr ) { return ( ptr == 0 ); }
    200 };
    201 
    202 template< class InputIterator, class OutputIterator, class Predicate >
    203 void filter(InputIterator begin, InputIterator end, OutputIterator out, Predicate pred) {
    204         while ( begin++ != end )
    205                 if ( pred(*begin) ) *out++ = *begin;
    206 
    207         return;
    208 }
    209 
    210 template< class InputIterator1, class InputIterator2, class OutputIterator >
    211 void zip( InputIterator1 b1, InputIterator1 e1, InputIterator2 b2, InputIterator2 e2, OutputIterator out ) {
    212         while ( b1 != e1 && b2 != e2 )
    213                 *out++ = std::pair<typename InputIterator1::value_type, typename InputIterator2::value_type>(*b1++, *b2++);
     172template< typename... Args >
     173auto filter(Args&&... args) -> decltype(std::copy_if(std::forward<Args>(args)...)) {
     174  return std::copy_if(std::forward<Args>(args)...);
     175}
     176
     177template< typename... Args >
     178auto zip(Args&&... args) -> decltype(zipWith(std::forward<Args>(args)..., std::make_pair)) {
     179  return zipWith(std::forward<Args>(args)..., std::make_pair);
    214180}
    215181
     
    221187
    222188// it's nice to actually be able to increment iterators by an arbitrary amount
    223 template< typename Iterator >
    224 Iterator operator+(Iterator i, int inc) {
    225         while ( inc > 0 ) {
    226                 ++i;
    227                 --inc;
    228         }
    229         return i;
     189template< class InputIt, class Distance >
     190InputIt operator+( InputIt it, Distance n ) {
     191        advance(it, n);
     192        return it;
    230193}
    231194
     
    246209        warn_single( params... );
    247210}
     211
     212// -----------------------------------------------------------------------------
     213// Ref Counted Singleton class
     214// Objects that inherit from this class will have at most one reference to it
     215// but if all references die, the object will be deleted.
    248216
    249217template< typename ThisType >
     
    265233std::weak_ptr<ThisType> RefCountSingleton<ThisType>::global_instance;
    266234
     235// -----------------------------------------------------------------------------
    267236// RAII object to regulate "save and restore" behaviour, e.g.
    268237// void Foo::bar() {
     
    279248};
    280249
     250// -----------------------------------------------------------------------------
     251// Helper struct and function to support
     252// for ( val : reverseIterate( container ) ) {}
     253// syntax to have a for each that iterates backwards
     254
    281255template< typename T >
    282256struct reverseIterate_t {
Note: See TracChangeset for help on using the changeset viewer.