2

Scratching my head. Given that I have the following integer sequence:

std::integer_sequence<int,0,1,2>

And I have the following template:

template<int a, int b, int c> void myFunction() {}

Is there any way to call the template with the integer sequence as template parameters?

myFunction<std::integer_sequence<int,0,1,2>>(); This does not compile

I found some examples here on stack overflow how to pass the integer sequence as function parameters, but unfortunately this is not an option in my case. I can't use a parameter pack either as I already use a parameter pack for other things in the same context.

I am using C++17

Help is highly appreciated!

1
  • 3
    This is pretty unclear " I can't use a parameter pack either as I already use a parameter pack for other things in the same context." Please post a minimal reproducible example Commented Apr 30, 2021 at 9:29

1 Answer 1

3

You might write a helper template, e.g.

template<typename T, T... I>
auto helper(std::integer_sequence<T, I...>)
{
    myFunction<I...>();
}

Then call it as

helper(std::integer_sequence<int,0,1,2>{});

LIVE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.