File indexing completed on 2025-01-18 09:54:07
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
0009 #define CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
0010
0011 #include <catch2/matchers/catch_matchers_templated.hpp>
0012 #include <catch2/internal/catch_move_and_forward.hpp>
0013
0014 namespace Catch {
0015 namespace Matchers {
0016
0017 template <typename Matcher>
0018 class AllMatchMatcher final : public MatcherGenericBase {
0019 Matcher m_matcher;
0020 public:
0021 AllMatchMatcher(Matcher matcher):
0022 m_matcher(CATCH_MOVE(matcher))
0023 {}
0024
0025 std::string describe() const override {
0026 return "all match " + m_matcher.describe();
0027 }
0028
0029 template <typename RangeLike>
0030 bool match(RangeLike&& rng) const {
0031 for (auto&& elem : rng) {
0032 if (!m_matcher.match(elem)) {
0033 return false;
0034 }
0035 }
0036 return true;
0037 }
0038 };
0039
0040
0041 template <typename Matcher>
0042 class NoneMatchMatcher final : public MatcherGenericBase {
0043 Matcher m_matcher;
0044 public:
0045 NoneMatchMatcher(Matcher matcher):
0046 m_matcher(CATCH_MOVE(matcher))
0047 {}
0048
0049 std::string describe() const override {
0050 return "none match " + m_matcher.describe();
0051 }
0052
0053 template <typename RangeLike>
0054 bool match(RangeLike&& rng) const {
0055 for (auto&& elem : rng) {
0056 if (m_matcher.match(elem)) {
0057 return false;
0058 }
0059 }
0060 return true;
0061 }
0062 };
0063
0064
0065 template <typename Matcher>
0066 class AnyMatchMatcher final : public MatcherGenericBase {
0067 Matcher m_matcher;
0068 public:
0069 AnyMatchMatcher(Matcher matcher):
0070 m_matcher(CATCH_MOVE(matcher))
0071 {}
0072
0073 std::string describe() const override {
0074 return "any match " + m_matcher.describe();
0075 }
0076
0077 template <typename RangeLike>
0078 bool match(RangeLike&& rng) const {
0079 for (auto&& elem : rng) {
0080 if (m_matcher.match(elem)) {
0081 return true;
0082 }
0083 }
0084 return false;
0085 }
0086 };
0087
0088
0089 class AllTrueMatcher final : public MatcherGenericBase {
0090 public:
0091 std::string describe() const override;
0092
0093 template <typename RangeLike>
0094 bool match(RangeLike&& rng) const {
0095 for (auto&& elem : rng) {
0096 if (!elem) {
0097 return false;
0098 }
0099 }
0100 return true;
0101 }
0102 };
0103
0104
0105 class NoneTrueMatcher final : public MatcherGenericBase {
0106 public:
0107 std::string describe() const override;
0108
0109 template <typename RangeLike>
0110 bool match(RangeLike&& rng) const {
0111 for (auto&& elem : rng) {
0112 if (elem) {
0113 return false;
0114 }
0115 }
0116 return true;
0117 }
0118 };
0119
0120
0121 class AnyTrueMatcher final : public MatcherGenericBase {
0122 public:
0123 std::string describe() const override;
0124
0125 template <typename RangeLike>
0126 bool match(RangeLike&& rng) const {
0127 for (auto&& elem : rng) {
0128 if (elem) {
0129 return true;
0130 }
0131 }
0132 return false;
0133 }
0134 };
0135
0136
0137 template <typename Matcher>
0138 AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) {
0139 return { CATCH_FORWARD(matcher) };
0140 }
0141
0142
0143 template <typename Matcher>
0144 NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) {
0145 return { CATCH_FORWARD(matcher) };
0146 }
0147
0148
0149 template <typename Matcher>
0150 AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) {
0151 return { CATCH_FORWARD(matcher) };
0152 }
0153
0154
0155 AllTrueMatcher AllTrue();
0156
0157
0158 NoneTrueMatcher NoneTrue();
0159
0160
0161 AnyTrueMatcher AnyTrue();
0162 }
0163 }
0164
0165 #endif