callable_ref Class Template
Non-owning reference to a callable invoked with a Self_T& argument. More...
Declaration
class micro_os_plus::micro_test_plus::detail::callable_ref<Self_T> { ... }
Included Headers
Public Constructors Index
template <typename Callable_T> | |
| callable_ref (Callable_T &callable) noexcept | |
|
Constructs a reference to a callable. More... | |
Public Operators Index
template <typename Self_T> | |
| void | operator() (Self_T &self) const |
|
Invokes the referred callable. More... | |
Private Member Attributes Index
template <typename Self_T> | |
| void * | callable_ |
|
The address of the referred callable. More... | |
template <typename Self_T> | |
| void(*) | invoke_(void *callable, Self_T &self) |
|
The function that invokes the referred callable. More... | |
Private Static Functions Index
template <typename Callable_T> | |
| static void | invoke_callable (void *callable, Self_T &self) |
|
Invokes a callable of a given type, from its address. More... | |
Description
Non-owning reference to a callable invoked with a Self_T& argument.
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.
- Template Parameters
-
Self_T The type referred to by the argument of the callable (test_case).
Definition at line 1046 of file test.h.
Public Constructors
callable_ref()
| explicit noexcept |
Constructs a reference to a callable.
The callable must be invocable with a Self_T& argument, and must outlive the reference.
- Template Parameters
-
Callable_T The type of the callable object.
- Constraints
Callable_T is not a callable_ref, so that the copy constructor is used for copies.
- Parameters
-
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.
Declaration at line 1068 of file test.h, definition at line 483 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::callable_ref and micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::callable_.
Referenced by micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::callable_ref.
Public Operators
operator()()
| inline |
Invokes the referred callable.
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().
- Parameters
-
self The reference passed to the callable.
- Returns
Nothing.
Passes the stored address and self to the stored function.
Declaration at line 1085 of file test.h, definition at line 496 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::callable_ and micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::invoke_.
Private Member Attributes
callable_
|
The address of the referred callable.
Its type is erased; only invoke_ converts it back.
Definition at line 1112 of file test.h.
Referenced by micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::callable_ref and micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::operator().
invoke_
|
The function that invokes the referred callable.
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 micro_os_plus::micro_test_plus::detail::callable_ref< Self_T >::operator().
Private Static Functions
invoke_callable()
| static |
Invokes a callable of a given type, from its address.
Instantiated by the constructor for the type of the callable; its address is stored in invoke_.
- Template Parameters
-
Callable_T The type of the callable object.
- Parameters
-
callable The address of the callable, with its type erased.
self The reference passed to the callable.
- Returns
Nothing.
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.
Declaration at line 1104 of file test.h, definition at line 515 of file test-inlines.h.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.