6#ifndef MIMICPP_POLICIES_ARG_REQUIREMENT_POLICIES_HPP
7#define MIMICPP_POLICIES_ARG_REQUIREMENT_POLICIES_HPP
23 template <
typename Matcher>
29 template <
typename... Args>
30 requires std::invocable<
31 decltype(detail::matches_hook::matches),
37 constexpr bool operator()(Args&&... args)
const
39 std::is_nothrow_invocable_v<
40 decltype(detail::matches_hook::matches),
44 return detail::matches_hook::matches(
matcher, args...);
37 constexpr bool operator()(Args&&... args)
const {
…}
48 template <
typename Matcher,
typename MatchesStrategy,
typename DescribeStrategy>
55 MatchesStrategy matchesStrategy,
56 DescribeStrategy describeStrategy)
58 std::is_nothrow_move_constructible_v<Matcher>
59 && std::is_nothrow_move_constructible_v<MatchesStrategy>
60 && std::is_nothrow_move_constructible_v<DescribeStrategy>)
61 : m_Matcher{std::move(matcher)},
62 m_MatchesStrategy{std::move(matchesStrategy)},
63 m_DescribeStrategy{std::move(describeStrategy)}
73 template <
typename Return,
typename... Args>
74 requires std::is_invocable_r_v<bool, const MatchesStrategy&, matcher_matches_fn<Matcher>,
const call::Info<Return, Args...>&>
77 noexcept(std::is_nothrow_invocable_v<const MatchesStrategy&, matcher_matches_fn<Matcher>,
const call::Info<Return, Args...>&>)
85 template <
typename Return,
typename... Args>
95 detail::describe_hook::describe(m_Matcher));
100 [[no_unique_address]] MatchesStrategy m_MatchesStrategy;
101 [[no_unique_address]] DescribeStrategy m_DescribeStrategy;
109 template <std::size_t index, std::size_t... others>
110 struct arg_requirement_describer
116 out <<
"expect: arg[" << index;
117 ((out <<
", " << others), ...);
118 out <<
"] " << matcherDescription;
119 return std::move(out).str();
123 struct all_args_requirement_describer
129 out <<
"expect: arg[all] " << matcherDescription;
130 return std::move(out).str();
135 std::size_t... indices,
137 typename... Projections>
139 constexpr auto make_args_policy(
141 std::tuple<Projections...>&& projections)
144 sizeof...(indices) ==
sizeof...(Projections),
145 "Indices and projections size mismatch.");
147 using arg_selector_t = mimicpp::detail::args_selector_fn<
148 std::add_lvalue_reference_t,
149 std::index_sequence<indices...>>;
150 using apply_strategy_t = mimicpp::detail::arg_list_indirect_apply_fn<std::remove_cvref_t<Projections>...>;
151 using describe_strategy_t = arg_requirement_describer<indices...>;
154 std::forward<Matcher>(matcher),
155 mimicpp::detail::apply_args_fn(
157 apply_strategy_t{std::move(projections)}),
158 describe_strategy_t{}};
186 template <std::
size_t index,
typename Matcher,
typename Projection = std::
identity>
190 Projection&& projection = {})
192 std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>
193 && std::is_nothrow_constructible_v<std::remove_cvref_t<Projection>, Projection>)
195 return detail::make_args_policy<index>(
196 std::forward<Matcher>(matcher),
197 std::forward_as_tuple(std::forward<Projection>(projection)));
223 std::size_t... others,
225 typename... Projections>
227 constexpr auto args(Matcher&& matcher, Projections&&... projections)
229 std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>
230 && (... && std::is_nothrow_move_constructible_v<std::remove_cvref_t<Projections>>))
233 sizeof...(projections) <= 1u +
sizeof...(others),
234 "The projection count exceeds the amount of indices.");
236 return detail::make_args_policy<first, others...>(
237 std::forward<Matcher>(matcher),
238 mimicpp::detail::expand_tuple<std::identity, 1u +
sizeof...(others)>(
239 std::forward_as_tuple(std::forward<Projections>(projections)...)));
227 constexpr auto args(Matcher&& matcher, Projections&&... projections) {
…}
254 template <
typename Matcher>
257 noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>)
259 using arg_selector_t = mimicpp::detail::all_args_selector_fn<std::add_lvalue_reference_t>;
260 using apply_strategy_t = mimicpp::detail::arg_list_forward_apply_fn;
261 using describe_strategy_t = detail::all_args_requirement_describer;
264 std::forward<Matcher>(matcher),
265 mimicpp::detail::apply_args_fn(
268 describe_strategy_t{}};
Definition ArgRequirementPolicies.hpp:50
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition ArgRequirementPolicies.hpp:86
constexpr ArgsRequirement(Matcher matcher, MatchesStrategy matchesStrategy, DescribeStrategy describeStrategy) noexcept(std::is_nothrow_move_constructible_v< Matcher > &&std::is_nothrow_move_constructible_v< MatchesStrategy > &&std::is_nothrow_move_constructible_v< DescribeStrategy >)
Definition ArgRequirementPolicies.hpp:53
StringT describe() const
Definition ArgRequirementPolicies.hpp:91
static constexpr bool is_satisfied() noexcept
Definition ArgRequirementPolicies.hpp:68
constexpr bool matches(const call::Info< Return, Args... > &info) const noexcept(std::is_nothrow_invocable_v< const MatchesStrategy &, matcher_matches_fn< Matcher >, const call::Info< Return, Args... > & >)
Definition ArgRequirementPolicies.hpp:76
constexpr auto arg(Matcher &&matcher, Projection &&projection={}) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&std::is_nothrow_constructible_v< std::remove_cvref_t< Projection >, Projection >)
Checks whether the selected argument satisfies the given matcher.
Definition ArgRequirementPolicies.hpp:188
constexpr auto all_args(Matcher &&matcher) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher >)
Checks whether the all arguments satisfy the given matcher.
Definition ArgRequirementPolicies.hpp:256
constexpr auto args(Matcher &&matcher, Projections &&... projections) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&(... &&std::is_nothrow_move_constructible_v< std::remove_cvref_t< Projections > >))
Checks whether the selected arguments satisfy the given matcher.
Definition ArgRequirementPolicies.hpp:227
Definition ArgRequirementPolicies.hpp:106
Definition ArgRequirementPolicies.hpp:22
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition Printer.hpp:41
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:345
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:344
Definition ArgRequirementPolicies.hpp:25
const Matcher & matcher
Definition ArgRequirementPolicies.hpp:27