Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

invoke_intseq README

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.

Implementation Details

Header File: invoke_intseq.h

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:

  1. 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...).

  2. 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:

    1. void if the return type of f is void.

    2. A type satisfying the std::ranges::range concept if f returns a type over which we can iterate.

Recursive Invocation

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.

Additional Features

  • 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.

Example Usage

#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.

Build and Test

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.

Notes

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages