X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FSetVector.h;h=d2f7286c2596d66496ebc0018fc7e8865b9d61d8;hb=e19f11215d8fa29635b28317dd1cfd1915d048d4;hp=0ff0f46f88d2a8d81c84e9b6bf7d3e58a265e63b;hpb=75eac5f0ebff4d0ffe10ce6bc8f2867c5f15315b;p=oota-llvm.git diff --git a/include/llvm/ADT/SetVector.h b/include/llvm/ADT/SetVector.h index 0ff0f46f88d..d2f7286c259 100644 --- a/include/llvm/ADT/SetVector.h +++ b/include/llvm/ADT/SetVector.h @@ -141,15 +141,12 @@ public: /// \returns true if any element is removed. template bool remove_if(UnaryPredicate P) { - typename vector_type::iterator B = std::partition(vector_.begin(), - vector_.end(), - std::not1(P)), - E = vector_.end(); - if (B == E) + typename vector_type::iterator I + = std::remove_if(vector_.begin(), vector_.end(), + TestAndEraseFromSet(P, set_)); + if (I == vector_.end()) return false; - for (typename vector_type::iterator I = B; I != E; ++I) - set_.erase(*I); - vector_.erase(B, E); + vector_.erase(I, vector_.end()); return true; } @@ -188,6 +185,29 @@ public: } private: + /// \brief A wrapper predicate designed for use with std::remove_if. + /// + /// This predicate wraps a predicate suitable for use with std::remove_if to + /// call set_.erase(x) on each element which is slated for removal. + template + class TestAndEraseFromSet { + UnaryPredicate P; + set_type &set_; + + public: + typedef typename UnaryPredicate::argument_type argument_type; + + TestAndEraseFromSet(UnaryPredicate P, set_type &set_) : P(P), set_(set_) {} + + bool operator()(argument_type Arg) { + if (P(Arg)) { + set_.erase(Arg); + return true; + } + return false; + } + }; + set_type set_; ///< The set. vector_type vector_; ///< The vector. };