How to comprehend that template<typename Tp> bool is_array<Tp[]> = true is a partial specialization for template<typename T> bool is_array<Tp> = true?
Here is the related code snippet:
#include<iostream>
template<typename T>
bool is_array = false;
template<typename Tp>
bool is_array<Tp[]> = true;
int main()
{
std::cout << is_array<int> << std::endl;
std::cout << is_array<int[]> << std::endl;
}
I've also noticed that generally speaking, the number of template parameters in the partial template specialization is less than the number of template parameters in the primary template.
The partial specializations often are seen like this:
#include<iostream>
template<typename T, typename U>
class add
{
public:
add(T x, U y)
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
};
template<typename U>
class add<int, U>
{
public:
add(int x, U y)
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
};
int main()
{
add<int, double>(1, 5.0);
add<char, int>('a', 9);
}