![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
The tuple sub-package provides a facility for working with std::tuple.
The public header is
The Bazel target is
The tuple package provides facilities for applying invocables to the elements of a std::tuple.
Firstly, arene::base::apply invokes the supplied invocable once, with the elements of the tuple as arguments to the invocable:
Here, the values tuple is split into separate arguments and passed to the lambda, which then prints them out.
arene::base::for_each instead invokes the invocable for each element in turn:
In this case, the values tuple is again split, but now into separate function calls, so the do_print invocable is invoked 3 times: once with the int element, once with the double element, and finally once with the std::string element.
Finally, arene::base::for_each_index does the same splitting as arene::base::for_each, but additionally passes the index of the element to the operation as the first argument.
Here, the lambda is again called 3 times: first as lambda(0, "hello"), then as lambda(1, "world"), and finally as lambda(2, "goodbye").