Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
28 December 2022
This is the third of four episodes in a mini series on templates. The aim of the series is to help you understand some relatively complex template code.
In template code it is very common to see tests on the type of the classes involved: Is it an l-value, is it const, does it have a given method etc. These tests are called type traits.
In this episode we will investigate how they are implemented, which will build the final foundation for understanding some complex template code: for instance checking if two template parameters are the same type, and if the first one is an r-value - but that is for the next episode, in this we will investigate the building blocks.
We will implement our own versions of is_same_v, is_const_v, and integral_constant, and fortunately they end up being exactly the same as we have in the standard library.
Links:
* Type traits in the standard library: https://en.cppreference.com/w/cpp/header/type_traits
* Our scheduled trainings: https://training.kdab.com/
* Our onsite trainings: https://training.kdab.com/in-company-training/
0:00 Introduction
1:21 implementing std::is_same
4:45 difference between scheduled and onsite training
5:35 implementing std::is_const
8:30 std::integral_constant
14:00 Reviewing the code
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/template-mini-series/episode3