To my understanding, template specialization works as follows
template< typename T >
void dummy(T a)
std::cout<<a<<std::endl;
template<>
void dummy<int>(int a)
std::cout<<"special"<<std::endl;
};
I was looking at the following code which checks if something is a pointer or not:
template< typename T >
struct is_ptr{
constexpr static bool value = false;
};
template<typename T>
struct is_ptr<T*>{
constexpr static bool value = true;
};
Is this still a template specialization? Why is the line template <typename T>
there again in the specialization, and not <>
. Is it because multiple specializations are generated by the compiler whenever we have T*
rather than T
?
Would this code expand to
template<>
struct is_ptr<int*>
{
constexpr static bool value = true;
}
?
Aucun commentaire:
Enregistrer un commentaire