How does the compiler know two generic types are the same?

The compiler caches the result of comptime functions based on the input parameters. This is an important optimization to avoid having many duplicated of e.g. ArrayList(u8).

There are even easier ways to defeat this than random numbers. Since anonymous types are different each time, you can also just pass opaque{} in there. See for example C/C++ macro challenge #1: BOOST_PP_COUNTER - #4 by ianprime0509

Why would you want to defeat this though?

3 Likes