This C++20 project aims to implement a generalized version of std::invoke that handles arguments of type std::integer_sequence in a special way. The primary goal is to provide a mechanism for invoking a callable object with all possible combinations of values encoded in std::integer_sequence.
The header file invoke_intseq.h contains the implementation of the invoke_intseq function template. The template takes a callable object F that represent function and arguments Args. The behavior of the function is defined as follows:
-
If none of the arguments is of type std::integer_sequence, the invocation of invoke_intseq(f, args...) should have the same effect as std::invoke(f, args...), equivalent to calling f(args...).
-
If one or more arguments are of type std::integer_sequence, the function should invoke f for all possible combinations of elements encoded in the std::integer_sequence arguments. The result of the main invocation is:
-
void if the return type of f is void.
-
A type satisfying the std::ranges::range concept if f returns a type over which we can iterate.
-
For each argument of type std::integer_sequence<T, j_1, j_2, ..., j_m>, the invocation involves recursively calling invoke_intseq with different values of j_i. This leads to a sequence of recursive calls, exploring all possible combinations.
-
Perfect Forwarding: The implementation use perfect forwarding to avoid unnecessary copies of arguments passed by reference (lvalues) and take ownership of arguments passed by value (rvalues).
-
Constexpr: The invoke_intseq function is constexpr, allowing it to be evaluated at compile-time if all arguments (f and args...) are constexpr.
#include "invoke_intseq.h"
int main() {
auto func = [](int a, char b, double c) {
// Function implementation
};
invoke_intseq(func, 1, std::integer_sequence<int, 2, 3>, 'a', std::integer_sequence<double, 4.5, 6.7>);
return 0;
}In this example, invoke_intseq is used to invoke the func lambda with all possible combinations of values specified in the std::integer_sequence arguments.
To build and test the implementation, include the invoke_intseq.h header in your project and use it as described in the example above. Ensure that your project is configured to use C++20 features.
This README provides a high-level overview of the invoke_intseq implementation. For a detailed understanding, refer to the comments within the invoke_intseq.h file.