Consider this code:
constexpr int TEN = 10;
template < const int& >
struct Object { };
template < const int& II >
void test(Object<II>) { }
Then calls:
test<TEN>(Object<TEN>{});
test(Object<TEN>{});
The second call does not compile with the error message:
error: no matching function for call to βtest(Object<TEN>)
note: candidate: template<const int& II> void test(Object<II>)
note: template argument deduction/substitution failed:
note: couldn't deduce template parameter βIIβ
The question is why? Does this meet the standard?
And an even more important question: how can I solve this? That is: how can I help the compiler to derive a template parameter const int&?
In real code, instead int, it's harder for me literal type, so I need it const&. So, I canβt just use intinstead const int&. "
I use the gcc-7.0.1(snapshot), and I get the same error with parameters -std=c++11, -std=c++14, -std=c++17.