2 ms·
If `a` and `b` are typedefs to the same type, then `foo<a>` and `foo<b>` are literally the same type, so sharing code isn't a matter of compilers being “smart”
by catnaroek 11y ago
If `a` and `b` are typedefs to the same type, then `foo<a>` and `foo<b>` are literally the same type, so sharing code isn't a matter of compilers being “smart” - it's a matter of respecting C++'s semantics.
I think GP is talking about something different. Let's say you have two completely unrelated types `a` and `b`, but, for whatever reason, `foo<a>` and `foo<b>` happen to compile to exactly the same machine code. (For a concrete example, say `a` and `b` have the same size and alignment requirements, and say `foo` is `std::vector::reserve`.) Then either the compiler or the linker can “merge” the duplicated code for `foo<a>` and `foo<b>`.