File indexing completed on 2025-01-30 10:02:51
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
0009 #define CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
0010
0011 #include <catch2/matchers/catch_matchers_templated.hpp>
0012 #include <catch2/internal/catch_container_nonmembers.hpp>
0013 #include <catch2/internal/catch_move_and_forward.hpp>
0014
0015 namespace Catch {
0016 namespace Matchers {
0017
0018 class IsEmptyMatcher final : public MatcherGenericBase {
0019 public:
0020 template <typename RangeLike>
0021 bool match(RangeLike&& rng) const {
0022 #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
0023 using Catch::Detail::empty;
0024 #else
0025 using std::empty;
0026 #endif
0027 return empty(rng);
0028 }
0029
0030 std::string describe() const override;
0031 };
0032
0033 class HasSizeMatcher final : public MatcherGenericBase {
0034 std::size_t m_target_size;
0035 public:
0036 explicit HasSizeMatcher(std::size_t target_size):
0037 m_target_size(target_size)
0038 {}
0039
0040 template <typename RangeLike>
0041 bool match(RangeLike&& rng) const {
0042 #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
0043 using Catch::Detail::size;
0044 #else
0045 using std::size;
0046 #endif
0047 return size(rng) == m_target_size;
0048 }
0049
0050 std::string describe() const override;
0051 };
0052
0053 template <typename Matcher>
0054 class SizeMatchesMatcher final : public MatcherGenericBase {
0055 Matcher m_matcher;
0056 public:
0057 explicit SizeMatchesMatcher(Matcher m):
0058 m_matcher(CATCH_MOVE(m))
0059 {}
0060
0061 template <typename RangeLike>
0062 bool match(RangeLike&& rng) const {
0063 #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
0064 using Catch::Detail::size;
0065 #else
0066 using std::size;
0067 #endif
0068 return m_matcher.match(size(rng));
0069 }
0070
0071 std::string describe() const override {
0072 return "size matches " + m_matcher.describe();
0073 }
0074 };
0075
0076
0077
0078 IsEmptyMatcher IsEmpty();
0079
0080 HasSizeMatcher SizeIs(std::size_t sz);
0081 template <typename Matcher>
0082 std::enable_if_t<Detail::is_matcher<Matcher>::value,
0083 SizeMatchesMatcher<Matcher>> SizeIs(Matcher&& m) {
0084 return SizeMatchesMatcher<Matcher>{CATCH_FORWARD(m)};
0085 }
0086
0087 }
0088 }
0089
0090 #endif