DEV Community

Cover image for How the Hell C++ Templates Work ?

How the Hell C++ Templates Work ?

Tejas on December 04, 2023

Hey there, Welcome to a guide on C++ templates! 🎉 In this article, we will explore the ins and outs of using C++ templates and delve into the reaso...
Collapse
 
pgradot profile image
Pierre Gradot

Contrary to popular belief, C++ templates do not incur runtime overhead

This is true. People may confuse with the real performance issue with templates: they templates may incur compile time overhead (as each template instantiation must be compiled) and code size bloat (as each template instantiation must be stored).

Templates are a very powerful tool, but beginner (and intermediate too) developers must remember that they are just a tool. Templates are not hammers and all problems are not nails. I can recall when I was a young C++ learner, I wanted to use templates so I was looking for places to do so. Don't do that XD

Collapse
 
tejasgk profile image
Tejas

Yeah , I personally just use templates when I don't have to repeat the logic but still need the flexibility they provide.