11#pragma once
22
33#include < exception>
4+ #include < optional>
45#include < regex>
56#include < source_location>
67#include < string>
@@ -116,7 +117,9 @@ class Expectation {
116117 void to_match (std::string str, std::string msg = " " );
117118 void to_partially_match (std::regex regex, std::string msg = " " );
118119 void to_partially_match (std::string str, std::string msg = " " );
119- void to_satisfy (std::function<bool (A)> /* test*/ , std::string msg = "");
120+ template <typename F>
121+ requires std::invocable<F, A> && std::convertible_to<std::invoke_result_t <F, A>, bool >
122+ void to_satisfy (F test, std::string msg = " " );
120123 void to_start_with (std::string start, std::string msg = " " );
121124
122125 template <typename U>
@@ -355,8 +358,10 @@ void Expectation<A>::to_partially_match(std::regex regex, std::string msg) {
355358 * @return Whether the expectation succeeds or fails.
356359 */
357360template <typename A>
358- void Expectation<A>::to_satisfy(std::function<bool (A)> test, std::string msg) {
359- Matchers::Satisfy<A>(*this , test).set_message (std::move (msg)).run ();
361+ template <typename F>
362+ requires std::invocable<F, A> && std::convertible_to<std::invoke_result_t <F, A>, bool >
363+ void Expectation<A>::to_satisfy(F test, std::string msg) {
364+ Matchers::Satisfy<A>(*this , std::function<bool (A)>(std::move (test))).set_message (std::move (msg)).run ();
360365}
361366
362367template <typename A>
@@ -377,8 +382,8 @@ void Expectation<A>::to_end_with(std::string ending, std::string msg) {
377382
378383template <typename A>
379384template <typename U>
380- void Expectation<A>::to_end_with(std::initializer_list<U> start_sequence , std::string msg) {
381- Matchers::StartWith <A, std::initializer_list<U>>(*this , start_sequence ).set_message (std::move (msg)).run ();
385+ void Expectation<A>::to_end_with(std::initializer_list<U> end_sequence , std::string msg) {
386+ Matchers::EndWith <A, std::initializer_list<U>>(*this , end_sequence ).set_message (std::move (msg)).run ();
382387}
383388
384389template <typename A>
@@ -438,7 +443,7 @@ template <Util::is_functional F>
438443class ExpectationFunc : public Expectation <decltype (std::declval<F>()())> {
439444 using block_ret_t = decltype (std::declval<F>()());
440445 F block;
441- std::shared_ptr <block_ret_t > computed = nullptr ;
446+ std::optional <block_ret_t > computed = std:: nullopt ;
442447
443448 public:
444449 ExpectationFunc (ExpectationFunc<F> const & copy, std::source_location location)
@@ -473,8 +478,8 @@ class ExpectationFunc : public Expectation<decltype(std::declval<F>()())> {
473478
474479 /* * @brief Get the target of the expectation. */
475480 block_ret_t & get_target () & override {
476- if (computed == nullptr ) {
477- computed = std::make_shared< block_ret_t > (block ());
481+ if (! computed. has_value () ) {
482+ computed. emplace (block ());
478483 }
479484 return *computed;
480485 }
0 commit comments