My Introduction To Templates In Cpp A developer exploring C++ templates discovered they are a tool for creating functions and classes that work with any data type, eliminating the need for repetitive code. The developer demonstrated how templates can replace multiple overloaded functions for converting vectors to linked lists, improving code scalability and readability. A few days ago, on an impulse, I asked Gemini to provide me with a snippet of the source code underlying the std::cout function which I now know is not a function at all . The implicit goal was to get a feel of the low-leveledness involved in writing foundation tools in C++. The explicit goal was procrastination : Anyways, I got nothing out of the answer, which was fine with me. I did stumble across the notorious template as being one of the core concepts used. Ever since I started learning C++, templates have been present in the back of my mind as the end game of proficiency in the language not true of course . I remember seeing templates being used in random code I encountered and being intimidated by the capital T. Now I know that this fear was sustained entirely by ignorance, like most things in life. This time, I decided to understand how it actually worked. What the need was. And it turned out to be so damn simple that I had to smile in shame when I realized. Templates are nothing but a tool to create functions and classes where you don't know what kind of specific data you are going to work with. Or you do know, but there are too many and you need to work with them all the same way. The popular way to put it is that classes are to objects what templates are to classes. In other words, templates are blueprints for creating classes. More accurately, they can be used to create blueprints for functions too as will be shown later , but we can base our understanding starting from this thought. Let's consider the following helper function I wrote for testing an LC solution No. 21 : struct ListNodeInt { int val; ListNodeInt next; ListNodeInt int val : val val , next nullptr {} }; ListNodeInt vector to LL std::vector