Why following example:
#include <iostream>
#include <typeinfo>
template<typename T>
void fun(const T& param)
{
std::cout << "T = " << typeid(T).name() << std::endl;
std::cout << "param = " << typeid(param).name() << std::endl;
std::cout << (typeid(T)==typeid(param)) << std::endl;
}
int main(int, char**)
{
fun(1);
}
gives following output:
T is i
param is i
1
I know that type_info::name()
behaviour is implementation dependent. Anyway I would expect operator==
to return false
(because param
is a const reference and not an integer).
==
but in your question!=
. Clarify. – Westwardtypeid
ignores top-level qualifiers (including references). – Folderint
? If so, fine print:filter through c++filt -t if using gcc or similar.
– Fishmongertypeid
can be applied to either a type or an expression (just likesizeof
). The expressionparam
is of typeconst T
(remember, expressions are values, never references). Andtypeid
ignores the top-level cv-qualifiers. – Folder