Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Eric Fiselier | 74fb163 | 2018-11-21 20:39:24 +0000 | [diff] [blame] | 9 | #ifndef TEST_SUPPORT_COUNTING_PREDICATES_H |
| 10 | #define TEST_SUPPORT_COUNTING_PREDICATES_H |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 11 | |
Eric Fiselier | 74fb163 | 2018-11-21 20:39:24 +0000 | [diff] [blame] | 12 | #include <cstddef> |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 13 | |
Marshall Clow | 90ba0533 | 2014-08-04 17:32:25 +0000 | [diff] [blame] | 14 | template <typename Predicate, typename Arg> |
Stephan T. Lavavej | bc93376 | 2017-08-24 21:24:08 +0000 | [diff] [blame] | 15 | struct unary_counting_predicate { |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 16 | public: |
Stephan T. Lavavej | bc93376 | 2017-08-24 21:24:08 +0000 | [diff] [blame] | 17 | typedef Arg argument_type; |
| 18 | typedef bool result_type; |
| 19 | |
Marshall Clow | c8528b5 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 20 | unary_counting_predicate(Predicate p) : p_(p), count_(0) {} |
| 21 | ~unary_counting_predicate() {} |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 22 | |
Marshall Clow | c8528b5 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 23 | bool operator () (const Arg &a) const { ++count_; return p_(a); } |
| 24 | size_t count() const { return count_; } |
| 25 | void reset() { count_ = 0; } |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 26 | |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 27 | private: |
Marshall Clow | c8528b5 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 28 | Predicate p_; |
| 29 | mutable size_t count_; |
Eric Fiselier | 74fb163 | 2018-11-21 20:39:24 +0000 | [diff] [blame] | 30 | }; |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 31 | |
| 32 | |
| 33 | template <typename Predicate, typename Arg1, typename Arg2=Arg1> |
Stephan T. Lavavej | bc93376 | 2017-08-24 21:24:08 +0000 | [diff] [blame] | 34 | struct binary_counting_predicate { |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 35 | public: |
Stephan T. Lavavej | bc93376 | 2017-08-24 21:24:08 +0000 | [diff] [blame] | 36 | typedef Arg1 first_argument_type; |
| 37 | typedef Arg2 second_argument_type; |
| 38 | typedef bool result_type; |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 39 | |
Marshall Clow | c8528b5 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 40 | binary_counting_predicate ( Predicate p ) : p_(p), count_(0) {} |
| 41 | ~binary_counting_predicate() {} |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 42 | |
Marshall Clow | c8528b5 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 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; } |
Marshall Clow | 79d4ffb | 2014-07-09 21:04:22 +0000 | [diff] [blame] | 46 | |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 47 | private: |
Marshall Clow | c8528b5 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 48 | Predicate p_; |
| 49 | mutable size_t count_; |
Eric Fiselier | 74fb163 | 2018-11-21 20:39:24 +0000 | [diff] [blame] | 50 | }; |
Marshall Clow | 57e06df | 2014-06-06 22:33:40 +0000 | [diff] [blame] | 51 | |
Eric Fiselier | 74fb163 | 2018-11-21 20:39:24 +0000 | [diff] [blame] | 52 | #endif // TEST_SUPPORT_COUNTING_PREDICATES_H |