[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / support / counting_predicates.h
blob1868d30b471e9384f83d80c085b3b53ff3020a59
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 //===----------------------------------------------------------------------===//
9 #ifndef TEST_SUPPORT_COUNTING_PREDICATES_H
10 #define TEST_SUPPORT_COUNTING_PREDICATES_H
12 #include <cstddef>
14 template <typename Predicate, typename Arg>
15 struct unary_counting_predicate {
16 public:
17 typedef Arg argument_type;
18 typedef bool result_type;
20 unary_counting_predicate(Predicate p) : p_(p), count_(0) {}
21 ~unary_counting_predicate() {}
23 bool operator () (const Arg &a) const { ++count_; return p_(a); }
24 size_t count() const { return count_; }
25 void reset() { count_ = 0; }
27 private:
28 Predicate p_;
29 mutable size_t count_;
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;
40 binary_counting_predicate ( Predicate p ) : p_(p), count_(0) {}
41 ~binary_counting_predicate() {}
43 bool operator () (const Arg1 &a1, const Arg2 &a2) const { ++count_; return p_(a1, a2); }
44 size_t count() const { return count_; }
45 void reset() { count_ = 0; }
47 private:
48 Predicate p_;
49 mutable size_t count_;
52 #endif // TEST_SUPPORT_COUNTING_PREDICATES_H