Sequoia
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
sequoia::testing::tutor< Advisor > Class Template Reference

class template used to wrap function objects which proffer advice. More...

#include <Advice.hpp>

Public Types

using sequoia_advisor_type = Advisor
 

Public Member Functions

 tutor (Advisor a, std::string prefix="Advice: ")
 
template<class T >
requires use_advisor_v<Advisor, T>
std::string operator() (const T &value, const T &prediction) const
 
const std::string & prefix () const noexcept
 

Detailed Description

template<class Advisor>
class sequoia::testing::tutor< Advisor >

class template used to wrap function objects which proffer advice.

An appropriate instantiation of this class template may be supplied as the final argument of many of the check methods. For example, consider checking equality of an int:

check(equality, "", x, 41, tutor{[](int value, int prediction) {
    return value == 42 ? "Are you sure the universe isn't trying to tell you something?" : "";
}});

In the case the x != 41, not only will failure be reported in the usual manner but, if x == 42, some spectacularly useful advice will be proffered.

Matters are similar, though somewhat more subtle for types which specialize value_tester. Consider some type, T for which this is done. Perhaps T wraps an int in which case the specialization of value_tester will invoke a check for ints. In this case, the advice function object should generally provide an overload for ints, as above. Suppose instead that the overload is for Ts. This will only be called in this particular example if T can be implicitly constructed from an int; otherwise the advice function object will simply be ignored.

Note that in the case where the advice function object provides a single binary overload of operator() then narrowing conversions are forbidden. However, if there are multiple binary overloads, narrowing conversions may occur.


The documentation for this class was generated from the following file: