Skip to main content

bound_callable Class Template

Function object that holds a callable and the additional arguments it is invoked with. More...

Declaration​

template <typename Self_T, typename Callable_T, typename... Args_T>
class micro_os_plus::micro_test_plus::detail::bound_callable<Self_T, Callable_T, Args_T> { ... }

Included Headers​

Public Constructors Index​

template <typename C, typename... A>
constexprbound_callable (C &&callable, A &&... arguments)

Constructs the function object from a callable and the arguments. More...

Public Operators Index​

template <typename Self_T, typename Callable_T, typename... Args_T>
voidoperator() (Self_T &self)

Invokes the stored callable. More...

Private Member Functions Index​

template <std::size_t... Is>
voidinvoke (Self_T &self, std::index_sequence< Is... >)

Invokes the stored callable with the stored arguments, unpacked by their indices. More...

Private Member Attributes Index​

template <typename Self_T, typename Callable_T, typename... Args_T>
std::tuple< Args_T... >arguments_

The stored arguments. More...

template <typename Self_T, typename Callable_T, typename... Args_T>
Callable_Tcallable_

The stored callable. More...

Description​

Function object that holds a callable and the additional arguments it is invoked with.

Returned by bind_callable() when there are additional arguments. When invoked with a Self_T& reference, it invokes the stored callable with that reference, followed by the stored arguments, as non-const lvalues.

It replaces a lambda, since the function call operator of a lambda cannot be marked as always inlined in a way accepted by all the supported compilers; without optimisations, a separate frame for it would make the call chain of each nested test case longer.

Template Parameters
Self_T

The type referred to by the first parameter of the callable (test_case or suite).

Callable_T

The type of the stored callable (decayed).

Args_T

The types of the stored arguments (decayed).

Definition at line 943 of file test.h.

Public Constructors​

bound_callable()​

template <typename C, typename... A>
micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::bound_callable (C && callable, A &&... arguments)
explicit constexpr

Constructs the function object from a callable and the arguments.

Copies (or moves) the callable and the arguments into the object.

Template Parameters
C

The type of the callable, as passed.

A

The types of the arguments, as passed.

Constraints

At least one argument, so that the copy and move constructors are used for copies (there is always at least one stored argument, and the member initialisation requires one argument for each of them). The constraint does not refer to Args_T, since clang 17 and 18 crash on the out-of-line definition of a constraint that refers to the pack of the enclosing class.

Parameters
callable

The callable object.

arguments

The arguments passed to the callable after the leading reference.

The callable and the arguments are forwarded to the constructors of the members, which store decayed copies.

Declaration at line 970 of file test.h, definition at line 370 of file test-inlines.h.

371 C&& callable, A&&... arguments)
372 : callable_ (std::forward<C> (callable)),
373 arguments_ (std::forward<A> (arguments)...)
374 {
375 }

References micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::bound_callable, micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::arguments_ and micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::callable_.

Referenced by micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::bound_callable.

Public Operators​

operator()()​

template <typename Self_T, typename Callable_T, typename... Args_T>
void micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::operator() (Self_T & self)
inline

Invokes the stored callable.

Always inlined, so that, without optimisations, it adds no frame between callable_ref::invoke_callable() and the callable.

Parameters
self

The reference passed as the first argument.

Returns

Nothing.

Unpacks the stored arguments by their indices.

Declaration at line 984 of file test.h, definition at line 383 of file test-inlines.h.

384 {
385 invoke (self, std::index_sequence_for<Args_T...>{});
386 }

Reference micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::invoke.

Private Member Functions​

invoke()​

template <std::size_t... Is>
void micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::invoke (Self_T & self, std::index_sequence< Is... >)
inline

Invokes the stored callable with the stored arguments, unpacked by their indices.

Always inlined, as the function call operator.

Template Parameters
Is

The indices of the stored arguments.

Parameters
self

The reference passed as the first argument.

Returns

Nothing.

A function, 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 1002 of file test.h, definition at line 399 of file test-inlines.h.

400 Self_T& self, std::index_sequence<Is...>)
401 {
402 if constexpr (std::is_member_pointer_v<Callable_T>)
403 {
404 std::invoke (callable_, self, std::get<Is> (arguments_)...);
405 }
406 else
407 {
408 callable_ (self, std::get<Is> (arguments_)...);
409 }
410 }

References micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::arguments_ and micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::callable_.

Referenced by micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::operator().

Private Member Attributes​

arguments_​

template <typename Self_T, typename Callable_T, typename... Args_T>
std::tuple<Args_T...> micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::arguments_

The stored arguments.

Copies of the arguments passed to bind_callable(), decayed; a reference parameter of the callable refers to the copy.

Definition at line 1020 of file test.h.

1020 std::tuple<Args_T...> arguments_;

Referenced by micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::bound_callable and micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::invoke.

callable_​

template <typename Self_T, typename Callable_T, typename... Args_T>
Callable_T micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::callable_

The stored callable.

A copy of the callable passed to bind_callable(), decayed, so a function is stored as a pointer.

Definition at line 1011 of file test.h.

1011 Callable_T callable_;

Referenced by micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::bound_callable and micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::invoke.


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


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.