Simple and useful snippet that helps to make an unique identifier for any type in C++.

template <typename T>
std::uintptr_t getTypeId() {
	static int id;
	return reinterpret_cast<std::uintptr_t>(&id);

It uses a fact that function static member of a function is a part of template installation, hence it contains own, unique address.


1 Kudos