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

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-05-12 08:57:55 +0200
committerMartin Hořeňovský2026-05-12 11:05:29 +0200
commit3cdae5faf08b7a3861be5e7bf6f1968e9229f460 (patch)
tree883148c9b341e24169bce2595da512159450968e /src
parent651247c7f40eda6846fec736d2f9edac8949dacb (diff)
downloadcatch3-3cdae5faf08b7a3861be5e7bf6f1968e9229f460.tar.gz
Constexpr matching support in IsEmpty and SizeIs matchers
Diffstat (limited to 'src')
-rw-r--r--src/catch2/matchers/catch_matchers_container_properties.cpp8
-rw-r--r--src/catch2/matchers/catch_matchers_container_properties.hpp18
2 files changed, 10 insertions, 16 deletions
diff --git a/src/catch2/matchers/catch_matchers_container_properties.cpp b/src/catch2/matchers/catch_matchers_container_properties.cpp
index f0c535bc..6297221e 100644
--- a/src/catch2/matchers/catch_matchers_container_properties.cpp
+++ b/src/catch2/matchers/catch_matchers_container_properties.cpp
@@ -22,13 +22,5 @@ namespace Matchers {
return sstr.str();
}
- IsEmptyMatcher IsEmpty() {
- return {};
- }
-
- HasSizeMatcher SizeIs(std::size_t sz) {
- return HasSizeMatcher{ sz };
- }
-
} // end namespace Matchers
} // end namespace Catch
diff --git a/src/catch2/matchers/catch_matchers_container_properties.hpp b/src/catch2/matchers/catch_matchers_container_properties.hpp
index 33795fbe..552bbab1 100644
--- a/src/catch2/matchers/catch_matchers_container_properties.hpp
+++ b/src/catch2/matchers/catch_matchers_container_properties.hpp
@@ -18,7 +18,7 @@ namespace Catch {
class IsEmptyMatcher final : public MatcherGenericBase {
public:
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
#if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
using Catch::Detail::empty;
#else
@@ -33,12 +33,12 @@ namespace Catch {
class HasSizeMatcher final : public MatcherGenericBase {
std::size_t m_target_size;
public:
- explicit HasSizeMatcher(std::size_t target_size):
+ constexpr explicit HasSizeMatcher(std::size_t target_size):
m_target_size(target_size)
{}
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
#if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
using Catch::Detail::size;
#else
@@ -54,12 +54,12 @@ namespace Catch {
class SizeMatchesMatcher final : public MatcherGenericBase {
Matcher m_matcher;
public:
- explicit SizeMatchesMatcher(Matcher m):
+ constexpr explicit SizeMatchesMatcher(Matcher m):
m_matcher(CATCH_MOVE(m))
{}
template <typename RangeLike>
- bool match(RangeLike&& rng) const {
+ constexpr bool match(RangeLike&& rng) const {
#if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
using Catch::Detail::size;
#else
@@ -75,11 +75,13 @@ namespace Catch {
//! Creates a matcher that accepts empty ranges/containers
- IsEmptyMatcher IsEmpty();
+ inline CATCH_DESTRUCTOR_CONSTEXPR IsEmptyMatcher IsEmpty() { return {}; }
//! Creates a matcher that accepts ranges/containers with specific size
- HasSizeMatcher SizeIs(std::size_t sz);
+ inline CATCH_DESTRUCTOR_CONSTEXPR HasSizeMatcher SizeIs( std::size_t sz ) {
+ return HasSizeMatcher{ sz };
+ }
template <typename Matcher>
- std::enable_if_t<Detail::is_matcher_v<Matcher>,
+ constexpr std::enable_if_t<Detail::is_matcher_v<Matcher>,
SizeMatchesMatcher<Matcher>> SizeIs(Matcher&& m) {
return SizeMatchesMatcher<Matcher>{CATCH_FORWARD(m)};
}