Changeset 234223f


Ignore:
Timestamp:
Sep 7, 2017, 10:34:23 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
871cdb4
Parents:
26238c1
Message:

added FuncGuard?, similar to ValueGuard? but with before/after lambdas

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r26238c1 r234223f  
    255255        ~ValueGuardPtr() { if( ref ) *ref = old; }
    256256};
     257
     258template< typename aT >
     259struct FuncGuard {
     260        aT m_after;
     261
     262        template< typename bT >
     263        FuncGuard( bT before, aT after ) : m_after( after ) {
     264                before();
     265        }
     266
     267        ~FuncGuard() {
     268                m_after();
     269        }
     270};
     271
     272template< typename bT, typename aT >
     273FuncGuard<aT> makeFuncGuard( bT && before, aT && after ) {
     274        return FuncGuard<aT>( std::forward<bT>(before), std::forward<aT>(after) );
     275}
    257276
    258277template< typename T >
Note: See TracChangeset for help on using the changeset viewer.