Importance of templates?

Importance of templates?
0.0 0


From a game developing point of view, how important do you consider templates to be as a topic to know about in C++? Do you frequently use templates in your code?


Templates can be used or they cannot be used. You don’t need them, technically. I know many developers that never touch templates because they consider them scary.

I like using templates. Especially with auto as a return type. :slight_smile:


Alright, thanks. Would you share an example of something you would use templates to solve?


Here is a simple example:


Well, I have seen such examples before - in fact, I have been through that tutorial. However, since you stated “I like using templates.”, can you exemplify a case, in which template was the right tool, that you might remember?

I am aware of the fact that the usage of templates is more or less just general, but still, it would be interesting to see examples of usage in game developing situations.


Oh, I see. I use templates when I deal with SQLite. For example, I want to fetch different types of database records and they all go through the same process of how I act with them but the return type might be different. Template will allow the code re-use and flexible return type.