AMDGPU: Allow f16/bf16 for DS_READ_TR16_B64 gfx950 builtins (#118297)
[llvm-project.git] / libcxx / test / support / counting_predicates.h
blobdb7ee481991c4a2d93899e4653e8852756b69e73
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>
13 #include <utility>
14 #include "test_macros.h"
16 template <typename Predicate, typename Arg>
17 struct unary_counting_predicate {
18 public:
19 typedef Arg argument_type;
20 typedef bool result_type;
22 unary_counting_predicate(Predicate p) : p_(p), count_(0) {}
23 unary_counting_predicate(const unary_counting_predicate&) = default;
24 unary_counting_predicate& operator=(const unary_counting_predicate&) = default;
25 ~unary_counting_predicate() {}
27 bool operator () (const Arg &a) const { ++count_; return p_(a); }
28 std::size_t count() const { return count_; }
29 void reset() { count_ = 0; }
31 private:
32 Predicate p_;
33 mutable std::size_t count_;
37 template <typename Predicate, typename Arg1, typename Arg2=Arg1>
38 struct binary_counting_predicate {
39 public:
40 typedef Arg1 first_argument_type;
41 typedef Arg2 second_argument_type;
42 typedef bool result_type;
44 binary_counting_predicate ( Predicate p ) : p_(p), count_(0) {}
45 ~binary_counting_predicate() {}
47 bool operator () (const Arg1 &a1, const Arg2 &a2) const { ++count_; return p_(a1, a2); }
48 std::size_t count() const { return count_; }
49 void reset() { count_ = 0; }
51 private:
52 Predicate p_;
53 mutable std::size_t count_;
56 #if TEST_STD_VER > 14
58 template <class Predicate>
59 class counting_predicate {
60 Predicate pred_;
61 int* count_ = nullptr;
63 public:
64 constexpr counting_predicate() = default;
65 constexpr counting_predicate(Predicate pred, int& count) : pred_(std::move(pred)), count_(&count) {}
67 template <class... Args>
68 constexpr decltype(auto) operator()(Args&& ...args) {
69 ++(*count_);
70 return pred_(std::forward<Args>(args)...);
73 template <class... Args>
74 constexpr decltype(auto) operator()(Args&& ...args) const {
75 ++(*count_);
76 return pred_(std::forward<Args>(args)...);
80 template <class Predicate>
81 counting_predicate(Predicate pred, int& count) -> counting_predicate<Predicate>;
83 #endif // TEST_STD_VER > 14
85 #endif // TEST_SUPPORT_COUNTING_PREDICATES_H