template <bool ...T>
int some_function()
{
// this is the function with return type int
// I am not sure how to get the values into the function
}
// this is how I want to call the function
int temp = some_function<1,0,0,0>();
Any suggestion for the function declaration?
For your use case, you can use recursion to do what you want. To do that you need two overloads. One with just a single bool parameter, and another with two bool parameters plus the variadic part. That gives you access to each value individually as you recurse your way through the parameter pack. In this case that would look like
// quick and dirty pow fucntion. There are better ones out there like https://stackoverflow.com/a/101613/4342498
template <typename T, typename U>
auto pow(T base, U exp)
{
T ret = 1;
for (int i = 0; i < exp; ++i)
ret *= base;
return ret;
}
template <bool Last>
int some_function()
{
return Last;
}
template <bool First, bool Second, bool... Rest>
int some_function()
{
return First * pow(2, sizeof...(Rest) + 1) + some_function<Second, Rest...>();
}
int main()
{
std::cout << some_function<1,0,0,0>();
}
Which outputs:
8