1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef TEST_SUPPORT_COUNTING_PREDICATES_H
10 #define TEST_SUPPORT_COUNTING_PREDICATES_H
14 template <typename Predicate
, typename Arg
>
15 struct unary_counting_predicate
{
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; }
29 mutable size_t count_
;
33 template <typename Predicate
, typename Arg1
, typename Arg2
=Arg1
>
34 struct binary_counting_predicate
{
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; }
49 mutable size_t count_
;
52 #endif // TEST_SUPPORT_COUNTING_PREDICATES_H