From a game developing point of view, how important do you consider templates to be as a topic to know about in C++? Have you used templates as a part of developing games or similar? Neither do I really understand how important templates can be considered from a general point of view.
closed as primarily opinion-based by Philipp, Tyyppi_77, Alexandre Vaillancourt♦ Jan 10 '18 at 14:10
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
There are 2 aspects:
Consuming meta-programming, i.e. using templates written by others: The STL (Standard TEMPLATE Library) is a pillar of C++. Nowadays, developing a large C++ application - that includes most games - without using template classes like
shared_ptr<>means the developer doesn't know how to program in C++.
Producing meta-programming, i.e. writing templates: Oftentimes, one can get away without writing templates (often using polymorphism instead) by sacrificing a bit of performance, type safety, or both. If you want cutting edge performance, you need templates, if you don't, you can skip them. Additionally, due to the added type safety provided by templates, their use is strongly recommended if you write a library or other complex components that are to be used by others, as proper use of templates can make your interfaces easy to use right and hard to use wrong. In larger teams, it's common that some people write most of the template code, while most others merely use the templates.
Overall, if you don't want to write templates, C++ may not be the best programming language to chose. If you don't want the highest performance, you could use something like C# instead, unless you're choosing C++ because you're more familiar with the language. Yet if you're not familiar with templates, you're not familiar with C++. There are still plenty of valid reasons to chose C++ regardless, e.g. licensing, corporate constraints, supported target architectures, pre-existing libraries, etc.
Templates are a crucial part of C++, they enable flexibility and expressiveness without sacrificing type-safety or efficiency. They are C++'s implementation of generic programming.
They don't have any specific relationship to game development, but like all the other tools in the box they come in handy when you need them. They are typically more useful in "engine"-flavoured tasks, which need their characteristics, and less prominent in the gameplay code which sits on top and doesn't need to be fast or generic (that's also the part that can be written with a scripting language to get other benefits instead).
For an example, here is one of my answers about implementing a kind of component-based dispatching system. You can see that I've used templates extensively (and a hint of macros as well) to create a generic system, and then used it to write terser gameplay code.
Templates are especially useful for containers or similar types. Since you understand templates generally I will omit an explanation of them, and rather give an example instead.
Templates can be useful in game development (other than for simple containers) when using patterns like the object pool pattern, especially for particle pools. You might want to reuse the implementation for an object pool for different kinds of objects, like enemies, particles, or props. (The linked example does not use templates, but explains the pattern well.)
However, since this is mostly used for optimizing, it is mostly dependant whether one uses an engine that already abstracts instancing functionality, or one even wants to write a custom game engine, in which case it might be inevitable.
Depends what you mean by 'from a games development point of view'. I've developed games without using templates at all. I've worked for companies which insist on using the standard template library and encourage using templates as well as companies which ban stl & templates completely! If you would like to work in games development then its a good idea to understand them. When abused they can bloat code and make it less readable. Understanding their potential pitfalls is quite important.