constexpr function allows the function to be evaluated at compile time, but does not require that, so your answer is "maybe". It depends on the compiler's optimization settings.
§7.1.5[dcl.constexpr]/7
A call to a constexpr
function produces the same result as a call to an equivalent non-constexpr
function
in all respects except that a call to a constexpr
function can appear in a constant expression.
If you wish to have no runtime cost, you could force compile-time evaluation by assigning it to a constexpr variable, e.g.
constexpr auto foo = CompID<Foo>();
Also note that type_info.hash_code()
cannot be evaluated in compile-time (it is not a constexpr function, §18.7.1[type.info]/7). So your code is actually wrong.