Changeset 2bf9c37 for src/Common


Ignore:
Timestamp:
Sep 1, 2017, 2:39:52 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a984e65
Parents:
9b18044
Message:

Refactor Validate filter into utility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r9b18044 r2bf9c37  
    172172auto filter(Args&&... args) -> decltype(std::copy_if(std::forward<Args>(args)...)) {
    173173  return std::copy_if(std::forward<Args>(args)...);
     174}
     175
     176template <typename E, typename UnaryPredicate, template< typename, typename...> class Container, typename... Args >
     177void filter( Container< E *, Args... > & container, UnaryPredicate pred, bool doDelete ) {
     178        auto i = begin( container );
     179        while ( i != end( container ) ) {
     180                auto it = next( i );
     181                if ( pred( *i ) ) {
     182                        if ( doDelete ) {
     183                                delete *i;
     184                        } // if
     185                        container.erase( i );
     186                } // if
     187                i = it;
     188        } // while
    174189}
    175190
Note: See TracChangeset for help on using the changeset viewer.