micro-test-plus 6.0.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T > Class Template Reference

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

#include "micro-os-plus/micro-test-plus.h"

Public Member Functions

template<typename C, typename... A>
requires (sizeof...(A) > 0)
constexpr bound_callable (C &&callable, A &&... arguments)
 Constructs the function object from a callable and the arguments.
void operator() (Self_T &self)
 Invokes the stored callable.

Private Member Functions

template<std::size_t... Is>
void invoke (Self_T &self, std::index_sequence< Is... >)
 Invokes the stored callable with the stored arguments, unpacked by their indices.

Private Attributes

std::tuple< Args_T... > arguments_
 The stored arguments.
Callable_T callable_
 The stored callable.

Detailed Description

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 >

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_TThe type referred to by the first parameter of the callable (test_case or suite).
Callable_TThe type of the stored callable (decayed).
Args_TThe types of the stored arguments (decayed).

Definition at line 943 of file test.h.

Constructor & Destructor Documentation

◆ bound_callable()

template<typename Self_T, typename Callable_T, typename... Args_T>
requires (sizeof...(A) > 0)
template<typename C, typename... A>
requires (sizeof...(A) > 0)
micro_os_plus::micro_test_plus::detail::bound_callable< Self_T, Callable_T, Args_T >::bound_callable ( C && callable,
A &&... arguments )
explicitconstexpr

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

Template Parameters
CThe type of the callable, as passed.
AThe 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
callableThe callable object.
argumentsThe 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.

Definition at line 370 of file test-inlines.h.

374 {
375 }
Function object that holds a callable and the additional arguments it is invoked with.
Definition test.h:944
std::tuple< Args_T... > arguments_
The stored arguments.
Definition test.h:1020
Callable_T callable_
The stored callable.
Definition test.h:1011

References bound_callable(), arguments_, and callable_.

Referenced by bound_callable().

Member Function Documentation

◆ invoke()

template<typename Self_T, typename Callable_T, typename... Args_T>
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... >  )
inlineprivate

Always inlined, as the function call operator.

Template Parameters
IsThe indices of the stored arguments.
Parameters
selfThe 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.

Definition at line 399 of file test-inlines.h.

401 {
403 {
405 }
406 else
407 {
409 }
410 }

References arguments_, and callable_.

Referenced by operator()().

◆ 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

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

Parameters
selfThe reference passed as the first argument.
Returns
Nothing.

Unpacks the stored arguments by their indices.

Definition at line 383 of file test-inlines.h.

384 {
386 }
void invoke(Self_T &self, std::index_sequence< Is... >)
Invokes the stored callable with the stored arguments, unpacked by their indices.

References invoke().

Member Data Documentation

◆ 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_
private

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.

Referenced by bound_callable(), and 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_
private

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.

Referenced by bound_callable(), and invoke().


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