How to use CLASS TEMPLATES, type traits, partial and full class template specialization
*Help me keep doing these videos!*
This works relies on *your* support! You can show it in one of these ways:
📚 Start a FREE Audible trial: https://www.audibletrial.com/CodeForYourself
🛍️ Buy gear I use to make this video: https://github.com/cpp-for-yourself/sponsor/blob/main/amazon.md
💶 Directly become a sponsor on GitHub: https://github.com/sponsors/niosus
📺 Watch my videos *to the end* and leave comments
⁉️ Find *your* way to support this work here: https://github.com/cpp-for-yourself/sponsor/tree/main
Class templates with the ability to partially and fully specialize them are arguably what makes C++ so powerful! We cover most of what one needs to know about what class templates are, how to specialize them fully or partially as well as how it all plays its role if we want to implement type traits.
Before you watch this video I recommend you to watch these videos if you haven't already:
- *why* use templates: https://youtu.be/1Mrt1NM3KnI
- *what* templates do under the hood: https://youtu.be/NKvEbPVllRE
- *how* to use *function* templates: https://youtu.be/BZ626ZWPspc
*In this video we look at*
- Class method templates
- Class templates
- How they can be specialized partially and fully
- And as always some easy to follow examples as well as stories about what can go wrong with template specialization
We cover a lot of ground in this video, and it is quite long as much as I tried to keep it very short. Please do not hesitate to comment and tell me what you think or what I might have missed.
📚 As always, the script to the video with all the code examples lives here: https://github.com/cpp-for-yourself/supplementary-materials/blob/main/lectures/templates_how_classes.md
*Links*
- CppInsights example mentioned at 06:14 - https://cppinsights.io/s/6729874b
- Class Template Argument Deduction (CTAD) link: https://en.cppreference.com/w/cpp/language/class_template_argument_deduction
- Google C++ Code Style on CTAD: https://google.github.io/styleguide/cppguide.html#CTAD
- Howard Hinnant on vector of booleans: https://isocpp.org/blog/2012/11/on-vectorbool
- Herb Sutter on vector of booleans: http://www.gotw.ca/publications/mill09.htm
- Type traits: https://en.cppreference.com/w/cpp/header/type_traits
- is_integral: https://en.cppreference.com/w/cpp/types/is_integral
- Partial template specialization: https://en.cppreference.com/w/cpp/language/partial_specialization
*Join this channel to get access to perks*
https://www.youtube.com/channel/UCRm39hwBxsX-8yj2xs3OJjQ/join