6#ifndef MIMICPP_MATCHERS_COMMON_HPP
7#define MIMICPP_MATCHERS_COMMON_HPP
17#ifndef MIMICPP_DETAIL_IS_MODULE
21 #include <type_traits>
26 template <
typename Matcher>
30namespace mimicpp::detail::describe_hook
33 template <
typename Matcher>
40 } -> util::explicitly_convertible_to<std::optional<StringT>>;
43 return custom::matcher_traits<Matcher>{}.describe(matcher);
46 template <
typename Matcher>
48 constexpr auto describe_impl(util::priority_tag<0>
const , Matcher
const& matcher)
49 ->
decltype(matcher.describe())
51 { matcher.describe() } -> util::explicitly_convertible_to<std::optional<StringT>>;
54 return matcher.describe();
57 inline constexpr util::priority_tag<1> maxTag{};
61 template <
typename Matcher>
63 constexpr auto operator()(Matcher
const& matcher)
const
64 ->
decltype(describe_impl(maxTag, matcher))
66 { describe_impl(maxTag, matcher) } -> util::explicitly_convertible_to<std::optional<StringT>>;
69 return describe_impl(maxTag, matcher);
73 inline constexpr describe_fn describe{};
76namespace mimicpp::detail::matches_hook
78 template <
typename Matcher,
typename... Ts>
82 { custom::matcher_traits<Matcher>{}.matches(matcher, targets...) } -> std::convertible_to<expectation::MatchResult>;
85 return custom::matcher_traits<Matcher>{}.matches(matcher, targets...);
88 template <
typename Matcher,
typename... Ts>
92 { matcher.matches(targets...) } -> std::convertible_to<expectation::MatchResult>;
95 return matcher.matches(targets...);
99 template <
typename Matcher,
typename... Ts>
103 { custom::matcher_traits<Matcher>{}.matches(matcher, targets...) } -> util::boolean_testable;
107 requires{{describe_hook::describe(matcher)}-> util::explicitly_convertible_to<std::optional<StringT>>; },
108 "A legacy matcher requires an appropriate describe-hook.");
110 if (custom::matcher_traits<Matcher>{}.matches(matcher, targets...))
112 return expectation::MatchSuccess{.description = std::optional<StringT>{describe_hook::describe(matcher)}};
115 return expectation::MatchFailure{.description = std::optional<StringT>{describe_hook::describe(matcher)}};
118 template <
typename Matcher,
typename... Ts>
122 { matcher.matches(targets...) } -> util::boolean_testable;
126 requires {{describe_hook::describe(matcher)}-> util::explicitly_convertible_to<std::optional<StringT>>; },
127 "A legacy matcher requires an appropriate describe-hook.");
129 if (matcher.matches(targets...))
131 return expectation::MatchSuccess{.description = std::optional<StringT>{describe_hook::describe(matcher)}};
134 return expectation::MatchFailure{.description = std::optional<StringT>{describe_hook::describe(matcher)}};
137 inline constexpr util::priority_tag<3> maxTag{};
141 template <
typename Matcher,
typename T,
typename... Others>
145 { matches_impl(maxTag, matcher, target, others...) } -> std::convertible_to<expectation::MatchResult>;
148 return matches_impl(maxTag, matcher, target, others...);
152 inline constexpr matches_fn matches{};
164 template <
typename Matcher,
typename... Args>
165 struct is_matcher_accepting
166 :
public std::true_type
170 template <
template <
typename...>
typename is_accepting,
typename... Args>
171 struct is_matcher_accepting_helper
172 :
public is_accepting<Args...>
181 template <
typename Matcher,
typename... Args>
182 requires requires {
typename is_matcher_accepting_helper<Matcher::template is_accepting, Args...>; }
183 struct is_matcher_accepting<Matcher, Args...>
184 :
public is_matcher_accepting_helper<Matcher::template is_accepting, Args...>
199 template <
typename Matcher,
typename... Args>
205 template <
typename T,
typename First,
typename... Others>
207 && std::is_move_constructible_v<T>
208 && std::destructible<T>
210 &&
requires(T
const& matcher, First& first, Others&... others) {
211 { detail::matches_hook::matches(matcher, first, others...) } -> std::convertible_to<expectation::MatchResult>;
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
Definition Common.hpp:206
std::variant< MatchSuccess, MatchFailure > MatchResult
Definition Common.hpp:41
constexpr bool is_matcher_accepting_v
Determines, whether the given Matcher accepts the specified Args.
Definition Common.hpp:200
Definition PriorityTag.hpp:24