#include <iostream>
#include <typeinfo> // The header <typeinfo> must be included before using typeid
// (if the header is not included, every use of the keyword typeid makes the program ill-formed.)
// https://en.cppreference.com/w/cpp/language/typeidtemplate<typename T>
void foo(T t) {
std::cout << "Generic foo(T t) for " << typeid(t).name() << std::endl;
}
template<typename T>
void foo(T* t) {
std::cout << "Specific foo(T* t) for " << typeid(t).name() << std::endl;
}
int main()
{
foo( nullptr ) ; // generic with T == std::nullptr_t
foo( &std::type_info::name ) ; // generic with T == const char* (std::type_info::*)() const
// foo( std::cout ) ; // *** error ***
}