Since there is no template<typename T, typename T> ... is_same
declaration, why the compiler doesn't give an error or at least choose template<typename T, typename U> is_same
when is_same<int, int>
is used?
- Shouldn't number of types used in
<>
match a template with same number of types? - The
template<typename T, typename U> ... is_same
doesn't have brackets afteris_same
token, so why does the compiler still generate... is_same<int, float> = false
with brackets?
CODE
template<typename T, typename U>
constexpr bool is_same = false;
template<typename T>
constexpr bool is_same<T,T> = true;
int main()
{
std::cout << is_same<int, int>;
std::cout << is_same<int, float>;
}
COMPILER OUTPUT
template<typename T, typename U>
constexpr const bool is_same = false;
template<>
constexpr const bool is_same<int, int> = true;
template<>
constexpr const bool is_same<int, float> = false;
template<typename T>
constexpr bool is_same<T,T> = true;
int main()
{
std::cout.operator<<(is_same<int, int>);
std::cout.operator<<(is_same<int, float>);
return 0;
}