|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Non-owning reference to a callable invoked with a Self_T& argument. More...
#include "micro-os-plus/micro-test-plus.h"
Public Member Functions | |
| template<typename Callable_T> requires (!std::is_same_v<std::remove_cv_t<Callable_T>, callable_ref<Self_T>>) | |
| callable_ref (Callable_T &callable) noexcept | |
| Constructs a reference to a callable. | |
| void | operator() (Self_T &self) const |
| Invokes the referred callable. | |
Static Private Member Functions | |
| template<typename Callable_T> | |
| static void | invoke_callable (void *callable, Self_T &self) |
| Invokes a callable of a given type, from its address. | |
Private Attributes | |
| void * | callable_ |
| The address of the referred callable. | |
| void(*) | invoke_ (void *callable, Self_T &self) |
| The function that invokes the referred callable. | |
Holds the address of the callable and a pointer to a function, instantiated for its type, which converts the address back and invokes the callable. Unlike a std::function, it neither copies the callable nor allocates memory, so the callable must outlive the reference.
A test case refers to its body this way, since the body is a local object of runnable_base::create_test_case(), which runs the test case and destroys it before returning.
| Self_T | The type referred to by the argument of the callable (test_case). |
|
explicitnoexcept |
The callable must be invocable with a Self_T& argument, and must outlive the reference.
| Callable_T | The type of the callable object. |
| callable | The callable object; an lvalue, possibly const, in which case it must be callable as const. |
Stores the address of the callable, and the address of the invoke_callable() instantiation for its type.
Definition at line 483 of file test-inlines.h.
References callable_ref(), and callable_.
Referenced by callable_ref().
|
staticprivate |
Instantiated by the constructor for the type of the callable; its address is stored in invoke_.
| Callable_T | The type of the callable object. |
| callable | The address of the callable, with its type erased. |
| self | The reference passed to the callable. |
Casts callable back to Callable_T*, the type it had when the reference was constructed, and invokes the callable through it, as an lvalue, with self.
A function pointer or a function object is called directly, not through std::invoke(), which, without optimisations, adds three frames to the call chain; a pointer to a member, which only std::invoke() can call, is still passed to it.
Definition at line 515 of file test-inlines.h.
|
inline |
Not noexcept, since a failed require() stops the body of a test case by throwing an exception.
Always inlined, so that, without optimisations, it adds no frame between test_case::run() and invoke_callable().
| self | The reference passed to the callable. |
Passes the stored address and self to the stored function.
Definition at line 496 of file test-inlines.h.
|
private |
Its type is erased; only invoke_ converts it back.
Definition at line 1112 of file test.h.
Referenced by callable_ref(), and operator()().
|
private |
The invoke_callable() instantiation for the type of the callable; it receives callable_ and the Self_T& argument.
Definition at line 1121 of file test.h.
Referenced by operator()().