Do Use C++ Algorithms!

preview_player
Показать описание
You have likely heard it before - "no raw for loops, use algorithms instead".

In this episode Jesper will give a few examples of code that became much cleaner when rewritten from raw loops to algorithms.
Further, he will introduce an algorithm library he had written to make it much less painful to write code using algorithms.

Links:

0:00 Introduction
1:07 Introduction to KDAlgorithms
1:38 The problem with the for_each algorithm
2:53 transform - as a loop
3:28 std::transform
4:25 std::transform in C++20
4:53 std::transform in C++23
5:34 kdalgorithms::transformed
8:00 kdalgorithms::transformed - converting the result type
8:37 kdalgorithms::filtered
11:19 kdalgorithms::all_of
12:11 Feedback please
12:42 Modernizing some old code - understanding the old code.
16:08 Now updating it to algorithms
22:07 A few more notes on KDAlgorithms

The example code showcased in this video is available here:

All Qt Widgets and more videos:

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrolment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Рекомендации по теме
Комментарии
Автор

Hi, Jesper, massive thanks for your videos and blogs. Your recent blog on qAsConst is very helpful to me.

echosystemd
Автор

Very interesting and thought inspiring presentation. Thanks a lot. I have not yet seen the algorithms code in details and I will definitely have a look very soon. I however have three questions:

1) Is it safe using these algorithms with Qt containers without risk of unwanted detachment?
2) Do the algorithms benefit from using reserve() for the output containers when the size is known?
3) Are they really zero-cost-abstraction? Do not they generate more complex machine code than good old plain loops (considering the loop is done correctly)?

(If you mentioned these points in the presentation, then I apologize, I probably overlooked it.)

vladimirkraus
Автор

Thanks for sharing, this was quite interesting.

greob