Check if two types are the same without template instantiations Below is my attempt to check if two types are the same without template instantiations.
#include &lt;cstddef&gt;
template&lt;class, class&gt; struct twoTypes;
template&lt;class T&gt; std::size_t isSame(twoTypes&lt;T,T&gt;*);
bool isSame(void*);

template&lt;class T, class U&gt;
using checkIfSame = decltype(isSame(static_cast&lt;twoTypes&lt;T,U&gt;*&gt;(0)));

And to check if they're the same, checkIfSame's size will be compared to std::size_t's size:
static_assert(sizeof(checkIfSame&lt;int,int&gt;) == sizeof(std::size_t)); //They're the same
static_assert(sizeof(checkIfSame&lt;const int,int&gt;) == sizeof(bool)); //Not the same

Are there any cases where my code will give the wrong result? My benchmarks show my version compiling faster than std::is_same, but are there any ways to make it faster?
If you're using clang or GCC ≥10, you can use the __is_same(type1, type2) intrinsic.
For portability:
#if !defined(__is_same) &amp;&amp; (!defined(__clang__) || !defined(__GNUC__) || __GNUC__ &lt; 10)
#define IS_SAME(T1, T2) std::is_same_v&lt;T1, T2&gt;
#else
#define IS_SAME(T1, T2) __is_same(T1, T2)
#endif