Comment Re:Can be faster (Score 1) 621
Templates in C++ are code generators--a C code generator could do the same thing, but it may not be type-safe. One of the purposes of inline functions and templates is to give developers an alternative to using unsafe C macros. A huge advantage of templates is their type safety; the STL's std::sort algorithm is much less error-prone than comparing void pointers from qsort.
Since a function call is usually only a few instructions, the cost of a function call is usually negligible for everything except simple expressions (like comparisons). In fact, many C++ compilers will refuse to inline functions that contain a loop. Mindlessly inlining non-trivial functions results in code bloat, increasing the code size as well as the chance of a cache miss.
Many virtual machines (Java and possibly the CLR) do runtime inlining. If a function is called often enough, the Java Hotspot VM will generate new JIT'd machine code with the function inlined. Because the code is generated on the fly, there is no need to reserve space for the dynamically inlined code.