• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEST_SUPPORT_COUNTING_PREDICATES_H
10 #define TEST_SUPPORT_COUNTING_PREDICATES_H
11 
12 #include <cstddef>
13 
14 template <typename Predicate, typename Arg>
15 struct unary_counting_predicate {
16 public:
17     typedef Arg argument_type;
18     typedef bool result_type;
19 
unary_counting_predicateunary_counting_predicate20     unary_counting_predicate(Predicate p) : p_(p), count_(0) {}
~unary_counting_predicateunary_counting_predicate21     ~unary_counting_predicate() {}
22 
operatorunary_counting_predicate23     bool operator () (const Arg &a) const { ++count_; return p_(a); }
countunary_counting_predicate24     size_t count() const { return count_; }
resetunary_counting_predicate25     void reset() { count_ = 0; }
26 
27 private:
28     Predicate p_;
29     mutable size_t count_;
30 };
31 
32 
33 template <typename Predicate, typename Arg1, typename Arg2=Arg1>
34 struct binary_counting_predicate {
35 public:
36     typedef Arg1 first_argument_type;
37     typedef Arg2 second_argument_type;
38     typedef bool result_type;
39 
binary_counting_predicatebinary_counting_predicate40     binary_counting_predicate ( Predicate p ) : p_(p), count_(0) {}
~binary_counting_predicatebinary_counting_predicate41     ~binary_counting_predicate() {}
42 
operatorbinary_counting_predicate43     bool operator () (const Arg1 &a1, const Arg2 &a2) const { ++count_; return p_(a1, a2); }
countbinary_counting_predicate44     size_t count() const { return count_; }
resetbinary_counting_predicate45     void reset() { count_ = 0; }
46 
47 private:
48     Predicate p_;
49     mutable size_t count_;
50 };
51 
52 #endif // TEST_SUPPORT_COUNTING_PREDICATES_H
53