Fix PR#202520 - predicate called too many times in list::remove_if. Add tests for list, forward_list, and the std::remove_if algorithm

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@214736 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2014-08-04 17:32:25 +00:00
parent a1d32fcd0e
commit f0f1bca861
5 changed files with 79 additions and 19 deletions

View File

@@ -11,16 +11,13 @@
#define __COUNTING_PREDICATES_H
template <typename Predicate>
struct unary_counting_predicate {
template <typename Predicate, typename Arg>
struct unary_counting_predicate : public std::unary_function<Arg, bool> {
public:
unary_counting_predicate(Predicate p) : p_(p), count_(0) {}
~unary_counting_predicate() {}
typedef typename Predicate::argument_type argument_type;
typedef bool result_type;
bool operator () (const argument_type &a) const { ++count_; return p_(a); }
bool operator () (const Arg &a) const { ++count_; return p_(a); }
size_t count() const { return count_; }
void reset() { count_ = 0; }