Type detection: Difference between revisions

Content added Content deleted
No edit summary
Line 128: Line 128:
3 is a hexadecimal digit
3 is a hexadecimal digit
</pre>
</pre>

=={{header|C++}}==
{{trans|D}}
<lang cpp>#include <iostream>

template <typename T>
auto typeString(const T&) {
return typeid(T).name();
}

class C {};
struct S {};

int main() {
std::cout << typeString(1) << '\n';
std::cout << typeString(1L) << '\n';
std::cout << typeString(1.0f) << '\n';
std::cout << typeString(1.0) << '\n';
std::cout << typeString('c') << '\n';
std::cout << typeString("string") << '\n';
std::cout << typeString(C{}) << '\n';
std::cout << typeString(S{}) << '\n';
std::cout << typeString(nullptr) << '\n';
}</lang>
{{out}}
<pre>int
long
float
double
char
char [7]
class C
struct S
std::nullptr_t</pre>


=={{header|Crystal}}==
=={{header|Crystal}}==