Yes, it will be correct to an extent. Template functions are implicitly inline
, and static objects in inline
functions are shared across all translation units.
So, in every translation unit, you will get the address of the same static local variable for the call to type_id<Type>()
. You are protected here from ODR violations by the standard.
Therefore, the address of the local static can be used as a sort of home-brewed run-time type identifier.