Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-05-12 09:25:50 +0200
committerMartin Hořeňovský2026-05-12 11:05:31 +0200
commitc267b6eb4de6d9ccdde238334c1248c7b60b8c0b (patch)
treea16676b23daa11fe15d3dfdddfab7e9dc7601325 /src/catch2
parent3cdae5faf08b7a3861be5e7bf6f1968e9229f460 (diff)
downloadcatch3-c267b6eb4de6d9ccdde238334c1248c7b60b8c0b.tar.gz
Constexpr matching support in the quantifier matchers
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/matchers/catch_matchers_quantifiers.cpp6
-rw-r--r--src/catch2/matchers/catch_matchers_quantifiers.hpp45
2 files changed, 25 insertions, 26 deletions
diff --git a/src/catch2/matchers/catch_matchers_quantifiers.cpp b/src/catch2/matchers/catch_matchers_quantifiers.cpp
index 5a752467..aeb1cc40 100644
--- a/src/catch2/matchers/catch_matchers_quantifiers.cpp
+++ b/src/catch2/matchers/catch_matchers_quantifiers.cpp
@@ -9,16 +9,12 @@
namespace Catch {
namespace Matchers {
- std::string AllTrueMatcher::describe() const { return "contains only true"; }
- AllTrueMatcher AllTrue() { return AllTrueMatcher{}; }
+ std::string AllTrueMatcher::describe() const { return "contains only true"; }
std::string NoneTrueMatcher::describe() const { return "contains no true"; }
- NoneTrueMatcher NoneTrue() { return NoneTrueMatcher{}; }
-
std::string AnyTrueMatcher::describe() const { return "contains at least one true"; }
- AnyTrueMatcher AnyTrue() { return AnyTrueMatcher{}; }
} // namespace Matchers
} // namespace Catch
diff --git a/src/catch2/matchers/catch_matchers_quantifiers.hpp b/src/catch2/matchers/catch_matchers_quantifiers.hpp
index 977b0c76..56684648 100644
--- a/src/catch2/matchers/catch_matchers_quantifiers.hpp
+++ b/src/catch2/matchers/catch_matchers_quantifiers.hpp
@@ -18,7 +18,7 @@ namespace Catch {
class AllMatchMatcher final : public MatcherGenericBase {
Matcher m_matcher;
public:
- AllMatchMatcher(Matcher matcher):
+ constexpr AllMatchMatcher(Matcher matcher):
m_matcher(CATCH_MOVE(matcher))
{}
@@ -27,7 +27,7 @@ namespace Catch {
}
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
for (auto&& elem : rng) {
if (!m_matcher.match(elem)) {
return false;
@@ -42,7 +42,7 @@ namespace Catch {
class NoneMatchMatcher final : public MatcherGenericBase {
Matcher m_matcher;
public:
- NoneMatchMatcher(Matcher matcher):
+ constexpr NoneMatchMatcher(Matcher matcher):
m_matcher(CATCH_MOVE(matcher))
{}
@@ -51,7 +51,7 @@ namespace Catch {
}
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
for (auto&& elem : rng) {
if (m_matcher.match(elem)) {
return false;
@@ -66,7 +66,7 @@ namespace Catch {
class AnyMatchMatcher final : public MatcherGenericBase {
Matcher m_matcher;
public:
- AnyMatchMatcher(Matcher matcher):
+ constexpr AnyMatchMatcher(Matcher matcher):
m_matcher(CATCH_MOVE(matcher))
{}
@@ -75,7 +75,7 @@ namespace Catch {
}
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
for (auto&& elem : rng) {
if (m_matcher.match(elem)) {
return true;
@@ -91,7 +91,7 @@ namespace Catch {
std::string describe() const override;
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
for (auto&& elem : rng) {
if (!elem) {
return false;
@@ -107,7 +107,7 @@ namespace Catch {
std::string describe() const override;
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
for (auto&& elem : rng) {
if (elem) {
return false;
@@ -123,7 +123,7 @@ namespace Catch {
std::string describe() const override;
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
for (auto&& elem : rng) {
if (elem) {
return true;
@@ -133,32 +133,35 @@ namespace Catch {
}
};
- // Creates a matcher that checks whether all elements in a range match a matcher
+ //! Creates a matcher that checks whether all elements in a range match a matcher
template <typename Matcher>
- AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) {
+ constexpr AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) {
return { CATCH_FORWARD(matcher) };
}
- // Creates a matcher that checks whether no element in a range matches a matcher.
+ //! Creates a matcher that checks whether no element in a range matches a matcher.
template <typename Matcher>
- NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) {
+ constexpr NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) {
return { CATCH_FORWARD(matcher) };
}
- // Creates a matcher that checks whether any element in a range matches a matcher.
+ //! Creates a matcher that checks whether any element in a range matches a matcher.
template <typename Matcher>
- AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) {
+ constexpr AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) {
return { CATCH_FORWARD(matcher) };
}
- // Creates a matcher that checks whether all elements in a range are true
- AllTrueMatcher AllTrue();
+ //! Creates a matcher that checks whether all elements in a range are true
+ inline CATCH_DESTRUCTOR_CONSTEXPR
+ AllTrueMatcher AllTrue() { return AllTrueMatcher{}; }
- // Creates a matcher that checks whether no element in a range is true
- NoneTrueMatcher NoneTrue();
+ //! Creates a matcher that checks whether no element in a range is true
+ inline CATCH_DESTRUCTOR_CONSTEXPR
+ NoneTrueMatcher NoneTrue() { return NoneTrueMatcher{}; }
- // Creates a matcher that checks whether any element in a range is true
- AnyTrueMatcher AnyTrue();
+ //! Creates a matcher that checks whether any element in a range is true
+ inline CATCH_DESTRUCTOR_CONSTEXPR
+ AnyTrueMatcher AnyTrue() { return AnyTrueMatcher{}; }
}
}