38 bool timesConfigured =
false;
39 bool finalizeConfigured =
false;
42 consteval BuilderState with(
bool(BuilderState::* option))
const noexcept
45 BuilderState copy{*
this};
46 std::invoke(option, copy) =
true;
52 template <
typename SequenceConfig,
typename FinalizePolicy,
typename... Policies>
53 struct BuilderPolicies
55 using FinalizePolicyType = FinalizePolicy;
57 using TimesConfig = policies::detail::TimesConfig;
59 SequenceConfig sequences{};
60 FinalizePolicy finalize{};
63 constexpr auto with_times(TimesConfig newTimes) &&
65 return BuilderPolicies{
72 template <
typename Policy>
73 constexpr auto with_sequences(Policy&& policy) &&
75 auto newSequences = sequences.concat(std::forward<Policy>(policy));
77 return BuilderPolicies<
decltype(newSequences), FinalizePolicy, Policies...>{
79 std::move(newSequences),
84 template <
typename Policy>
85 constexpr auto with_finalize(Policy&& policy) &&
87 return BuilderPolicies<SequenceConfig, std::remove_cvref_t<Policy>, Policies...>{
90 std::forward<Policy>(policy),
94 template <
typename Policy>
95 constexpr auto with_policy(Policy&& policy) &&
97 return BuilderPolicies<SequenceConfig, FinalizePolicy, Policies..., std::remove_cvref_t<Policy>>{
103 std::forward_as_tuple(std::forward<Policy>(policy)))};
108 template <
typename Signature, detail::BuilderState state,
typename Policies>
121 : m_Registry{std::move(registry)},
122 m_TargetReport{std::move(target)},
132 template <
typename Policy>
138 !std::same_as<policies::InitFinalize, std::remove_cvref_t<Policy>>,
139 "Explicitly specifying the `policies::InitFinalize` is disallowed.");
142 !state.finalizeConfigured,
143 "Only one finalize-policy may be specified per expectation. "
144 "See: https://dnkpp.github.io/mimicpp/db/d7a/group___e_x_p_e_c_t_a_t_i_o_n___f_i_n_a_l_i_z_e_r.html#details");
146 auto newPolicies = std::move(builder.m_Policies).with_finalize(std::forward<Policy>(policy));
149 state.with(&detail::BuilderState::finalizeConfigured),
150 decltype(newPolicies)>;
153 std::move(builder.m_Registry),
154 std::move(builder.m_TargetReport),
155 std::move(newPolicies)};
158 template <
typename Policy>
163 auto newPolicies = std::move(builder.m_Policies).with_policy(std::forward<Policy>(policy));
167 decltype(newPolicies)>;
170 std::move(builder.m_Registry),
171 std::move(builder.m_TargetReport),
172 std::move(newPolicies)};
179 !state.timesConfigured,
180 "Only one times-policy may be specified per expectation. "
181 "See: https://dnkpp.github.io/mimicpp/d7/d32/group___e_x_p_e_c_t_a_t_i_o_n___t_i_m_e_s.html#details");
185 state.with(&detail::BuilderState::timesConfigured),
189 std::move(builder.m_Registry),
190 std::move(builder.m_TargetReport),
191 std::move(builder.m_Policies).with_times(std::forward<TimesConfig>(config))};
194 template <
typename... Sequences>
198 auto newPolicies = std::move(builder.m_Policies).with_sequences(std::move(config));
202 decltype(newPolicies)>;
205 std::move(builder.m_Registry),
206 std::move(builder.m_TargetReport),
207 std::move(newPolicies)};
215 "For non-void return types, a finalize-policy must be specified. "
216 "See: https://dnkpp.github.io/mimicpp/db/d7a/group___e_x_p_e_c_t_a_t_i_o_n___f_i_n_a_l_i_z_e_r.html#details");
220 return m_Registry->create(
221 std::in_place_type<Signature>,
222 std::move(sourceLocation),
223 std::move(m_TargetReport),
225 std::move(m_Policies.finalize),
228 m_Policies.policies);
251 template <
string Param,
typename... Canary,
string Arg>
252 requires(!std::is_pointer_v<std::remove_reference_t<Param>>)
253 || (!std::is_pointer_v<std::remove_reference_t<Arg>>)
255 constexpr auto make_arg_matcher([[maybe_unused]] util::priority_tag<1>
const, Arg&& arg)
257 return matches::str::eq(std::forward<Arg>(arg));
260 template <
typename Param,
typename... Canary, util::weakly_equality_comparable_with<Param> Arg>
262 constexpr auto make_arg_matcher([[maybe_unused]] util::priority_tag<0>
const, Arg&& arg)
264 return matches::eq(std::forward<Arg>(arg));
267 inline constexpr util::priority_tag<2> maxMakeArgMatcherTag{};
280 template <
typename Arg,
typename Param>
283 detail::make_arg_matcher<Param>(detail::maxMakeArgMatcherTag, std::declval<Arg>())
296 constexpr auto make_arg_policy(Arg&& arg)
299 detail::make_arg_matcher<Param>(maxMakeArgMatcherTag, std::forward<Arg>(arg)));
302 template <
typename Signature,
typename Builder, std::size_t... indices,
typename... Args>
304 constexpr auto extend_builder_with_arg_policies(
306 std::index_sequence<indices...>
const ,
310 std::forward<Builder>(builder)
312 && detail::make_arg_policy<Signature, indices>(std::forward<Args>(args)));
315 template <
typename Signature,
typename... Args>
316 auto make_builder(Registry::Ptr registry, reporting::TargetReport target, Args&&... args)
318 using Policies = BuilderPolicies<sequence::detail::Config<>, policies::InitFinalize>;
319 using Builder = BasicBuilder<Signature, BuilderState{}, Policies>;
321 return detail::extend_builder_with_arg_policies<Signature>(
322 Builder{std::move(registry), std::move(target), Policies{}},
323 std::index_sequence_for<Args...>{},
324 std::forward<Args>(args)...);
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 RequirementPolicies.hpp:233