I encountered a case where I cannot understand the implicit conversion behavior in c++. The code is the following:
template <bool b, int i, unsigned... us>
void foo() {}
template <int i, unsigned... us>
void foo() {return foo<false, i, us...>();}
int main()
{
foo<true, -1, 0ul, 1ul, 2ul>(); // compiles with clang and gcc > 8 (gcc<=8 gives ambiguous function call)
foo<true, +1, 0ul, 1ul, 2ul>(); // ambiguous function call error
foo<-1, 0ul, 1ul, 3ul>(); // compiles with clang and gcc > 8 (gcc<=8 gives ambiguous function call)
foo<+1, 0ul, 1ul, 3ul>(); // ambiguous function call error
}
For line 1 and 2 in main(), the compiler seems to implicitly convert int to unsigned only for positive integers (this is understandable but is there a rule for this?)
For line 3 and 4 in main(), the compiler seems to implicitly convert int to bool only for positive integers. I cannot understand why.
Background: Ideally, I want to get a similar construct to work which effectly leads to a default value for the bool template parameter. But because of the parameter pack and c++ implicit builtin conversions, this seems to be difficult.