The following program does not compile:
#include <utility>
#include <iostream>
#define N 4
template <unsigned int I>
unsigned int g() { return I; }
template <unsigned int... I>
unsigned int f(std::integer_sequence<unsigned int, I...> = std::make_integer_sequence<unsigned int, N>{})
{
return (g<I>() + ...);
}
int main()
{
std::cout << f() << std::endl;
return 0;
}
Test it live on Coliru.
With gcc the error is
main.cpp: In function 'unsigned int f(std::integer_sequence<unsigned int, I ...>) [with unsigned int ...I = {}]':
main.cpp:17:18: error: could not convert 'std::make_integer_sequence<unsigned int, 4>{}' from 'integer_sequence<[...],'nontype_argument_pack' not supported by dump_expr>' to 'integer_sequence<[...],'nontype_argument_pack' not supported by dump_expr>'
A similar conversion error is reported with clang++:
error: no viable conversion from 'std::make_integer_sequence<unsigned int, 4>' (aka '__make_integer_seq<integer_sequence, unsigned int, 4U>') to 'std::integer_sequence'
Strangely enough, however, if I remove the default parameter, and pass the same expression to f, the program compiles and gives the corrected output:
#include <utility>
#include <iostream>
#define N 4
template <unsigned int I>
unsigned int g() { return I; }
template <unsigned int... I>
unsigned int f(std::integer_sequence<unsigned int, I...>)
{
return (g<I>() + ...);
}
int main()
{
std::cout << f(std::make_integer_sequence<unsigned int, N>{}) << std::endl;
return 0;
}
See it live on Coliru.
What's the problem/difference with the first code?