A template is a pattern, not code. Instantiation is the compile-time process where the compiler, seeing a use like max<int> or RingBuffer<uint8_t, 64>, generates a concrete, type-specific version by substituting the template parameters. It happens on demand: the compiler only instantiates the versions actually used, so max<double> exists in your binary only if something calls max with doubles. Each instantiation is a fully separate function or class, compiled and optimized as if you'd hand-written it for that type. Because all of this is resolved at compile time, the resulting code has zero runtime overhead, max<int>(3,7) is a direct call to an int-specific function, with no runtime type information or dispatch.
C++ for Embedded · Interview question
What is template instantiation and when does it happen?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Templates: The Basics
Write a function or class once and have the compiler stamp out a type-specific version for each use: generic code with zero runtime cost, plus the code-bloat tradeoff to watch.