But what C++ is doing (and static languages with metaprogramming in general) is specializing and statically inlining everything at compile time so the assembly just takes the fastest path every time; no runtime cost.
I'm unsure which static languages do and do not support partial specialization. My understanding is that the current iteration of Rust doesn't have partial specialization, but maybe it has other features that could do what this post is doing?
I'd be interested in hearing people's perspectives on the metaprogramming power of different statically typed languages - people have expressed interest in me building libraries like this in Rust and a few other languages.
Buuuut I'm probably missing something.
Besides, there are techniques to avoid dynamic dispatch for generic specializations, at least in C#.