Workshop: C++ Templates for Sceptics Applied
This workshop is for developers with C++ experience who have avoided templates so far. We start with the question what is generic programming. I then will introduce the different kinds of templates: function, class and method templates. We will walk through how to write and apply. Along with that we distinguish the different types of template parameters type, and non-type using std::array as an illustration).
This is accompanied by a peak behind the scenes by using C++ Insights (https://cppinsights.io). This should also give you a valuable tool where you can checkout details for yourself.
At this point we look at alias templates and how they can help us.
Once we covered the basics, we take care that our templates do not bloat the code. For that we use an example of passing an array and a length and optimize this. While on that, we consider at type_traits and incorporate them in our solution. With type_traits we use constexpr if for conditional compile-time code paths.
Next we go more into depth. We look at variadic templates by using a Printf like function as an example. This knowledge is then used to talk about template specializations.
At this point we will briefly talk about SFINAE. While we on that we will peak into C++20 and how Concepts make SFINAE way less scary.
Please note, this is a workshop with exercises. You should either have a C++17 development setup available or you can use https://godbolt.org.
After attending this talk, attendees have learned to think in types rather than in values. They have a good understanding of templates, including techniques like SFINAE and template specializations.