• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef TEST_SUPPORT_COUNTING_PREDICATES_H
11 #define TEST_SUPPORT_COUNTING_PREDICATES_H
12 
13 #include <cstddef>
14 
15 template <typename Predicate, typename Arg>
16 struct unary_counting_predicate {
17 public:
18     typedef Arg argument_type;
19     typedef bool result_type;
20 
unary_counting_predicateunary_counting_predicate21     unary_counting_predicate(Predicate p) : p_(p), count_(0) {}
~unary_counting_predicateunary_counting_predicate22     ~unary_counting_predicate() {}
23 
operator ()unary_counting_predicate24     bool operator () (const Arg &a) const { ++count_; return p_(a); }
countunary_counting_predicate25     size_t count() const { return count_; }
resetunary_counting_predicate26     void reset() { count_ = 0; }
27 
28 private:
29     Predicate p_;
30     mutable size_t count_;
31 };
32 
33 
34 template <typename Predicate, typename Arg1, typename Arg2=Arg1>
35 struct binary_counting_predicate {
36 public:
37     typedef Arg1 first_argument_type;
38     typedef Arg2 second_argument_type;
39     typedef bool result_type;
40 
binary_counting_predicatebinary_counting_predicate41     binary_counting_predicate ( Predicate p ) : p_(p), count_(0) {}
~binary_counting_predicatebinary_counting_predicate42     ~binary_counting_predicate() {}
43 
operator ()binary_counting_predicate44     bool operator () (const Arg1 &a1, const Arg2 &a2) const { ++count_; return p_(a1, a2); }
countbinary_counting_predicate45     size_t count() const { return count_; }
resetbinary_counting_predicate46     void reset() { count_ = 0; }
47 
48 private:
49     Predicate p_;
50     mutable size_t count_;
51 };
52 
53 #endif // TEST_SUPPORT_COUNTING_PREDICATES_H
54