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
19 July 2023
I've added sort_by to KDAlgorithms. This required that I, for C++14, had to implement what in C++17 is known as std::invoke.
In this video, I'll give you some insights into what that involved. It will, among a lot of other things, take us by:
- SFINAE and tag dispatching
- if constexpr
- parameter packs
- static_assert
Links:
* Type Traits: https://en.cppreference.com/w/cpp/header/type_traits
* Mini series on templates: https://youtu.be/BQEJ_HPLtps?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
* Episode on type traits: https://youtu.be/LzkxgfvvHqY?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
* Full version of the C++14 invoke in kdalgorithms: https://github.com/KDAB/KDAlgorithms/blob/main/src/kdalgorithms_bits/invoke.h
0:00 Introduction
1:12 The problem with std::sort
2:24 Introducing sort_by taking a member to sort by.
4:45 The problem to solve - std::invoke
5:44 sort_by in C++17 using std::invoke
6:14 Recapture - the building blocks
8:48 SFINAE
13:03 This is a simplified version
13:27 Pointers versus instances plus lambda's
16:02 What would invoke look like in C++17
18:56 Variable amount of arguments
21:12 Finally variable amount of arguments in the C++14 version
22:21 The final version is in github
All QML tips and tricks videos : https://www.youtube.com/playlist?list=PL6CJYn40gN6jWHP5krsQrVGyYtKh3A3be
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/invoke
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Learn Modern C++
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
Learn more