In 2019, I optimized QStringList::removeDuplicates() by using std::pmp::unordered_set with a std::pmr::monotonic_buffer_resource, when available. The class that I wrote to encapsulate this optimization has since been re-implemented three times. The latest iteration has recently landed in KDToolBox. If you have code that looks a bit like this: then you should read on.
Author Archives: Marc Mutz
QStringView Diaries: Zero-Allocation String Splitting QStringTokenizer merged for 6.0
After four months of intensive development work, I am happy to announce that the first QStringTokenizer commits have landed in what will eventually become Qt 6.0. The docs should show up, soon. While the version in Qt will be Qt 6-only, KDAB will release this tool for Qt 5 as part of its KDToolBox productivity […]
QStringView Diaries: Masters Of The Overloads How QStringView actively manages implicit conversions
The last blog post in this series described how to use string-views. This post is about how to design one. In particular, it’s about QStringView‘s constructors. They evolved through a rapid succession of changes. These changes either fixed ambiguities between QString and QStringView overloads, or improved performance. And they all have the same solution: std::enable_if, […]
QStringView Diaries: The Eagle Has Landed QStringView merged for Qt 5.10
After two months of intensive reviews, discussions, fixes, and stripping down the initial commit, feature by feature, to make it acceptable, I am happy to announce that the first QStringView commits have landed in what will eventually become Qt 5.10. Even the docs are already on-line. This is a good time to briefly recapitulate what […]
QStringView Diaries: Advances in QStringLiteral How QStringView Development Also Improves its "Competition"
This is the first in a series of blog posts on QStringView, the std::u16string_view equivalent for Qt. You can read about QStringView in my original post to the Qt development mailing-list, follow its status by tracking the “qstringview” topic on Gerrit and learn about string views in general in Marshall Clow’s CppCon 2015 talk, aptly […]
A Race is a Race is a Race is UB An example of the difference between int, volatile int, and std::atomic
In the last days, I was once again trying to convince fellow programmers that there’s no such thing as a “benign” data race. This is a recurring theme, in particular fueled by the docs of MSVC and Intel x86, which basically seem to say “you don’t need atomics here”. I perused the excellent papers Benign […]
Stepanov-Regularity and Partially-Formed Objects vs. C++ Value Types
In this article, I will take a look at one of the fundamental concepts introduced in Alex Stepanov and Paul McJones’ seminal book “Elements of Programming” (EoP for short) — that of a (Semi-)Regular Type and Partially-Formed State. Using these, I shall try to derive rules for C++ implementations of what are commonly called “value […]
Tuple And Pair in C++ APIs? A Simple Design Goal to Improve Your C++ APIs
Quick: When you design C++ APIs, when and how should you use pair and tuple? The answer is as simple as it is surprising: Never. Ever. When we design APIs, we naturally strive for qualities such as readability, ease-of-use, and discoverability. Some C++ types are enablers in this regard: std::optional, std::variant, std::string_view/gsl::string_span, and, of course, […]
Goodbye, Q_FOREACH A porting guide to C++11 ranged for-loops
Q_FOREACH (or the alternative form, foreach) will be deprecated soon, probably in Qt 5.9. Starting with Qt 5.7, you can use the QT_NO_FOREACH define to make sure that your code does not depend on Q_FOREACH. You may have wondered what all the fuss is about. Why is there a continuous stream of commits going to into Qt […]
Four Habit-Forming Tips to Faster C++
Are you a victim of premature pessimisation? Here’s a short definition from Herb Sutter: Premature pessimization is when you write code that is slower than it needs to be, usually by asking for unnecessary extra work, when equivalently complex code would be faster and should just naturally flow out of your fingers. Despite how amazing today’s […]