The above field is supplemented with consent to receive a newsletter containing information and marketing content about the cppstories.com portal from Bartłomiej Filipek codebf based in Krakow. The consent may be withdrawn at any time. See the full Privacy Policy.
Last week was an important milestone for my book: it got a print version available at Amazon! In this post, I’ll share some details behind the event and the plans.
The Print (on Demand) Since March 2019, I’ve been testing a few platforms that offer print on demand. One book came from Lulu.
Last week’s article about smaller C++17 features mentioned updated operator new() that handles non-standard alignment of objects. How does it work? Can you use it to ask for arbitrary alignments? Let’s try some code and have a closer look.
Last update: 9th September 2019
Why should you care about alignment? Let’s examine the first example:
C++11 brought Move Semantics. Since then we have extra capabilities to write faster code, support movable-only types, but also more headaches :). At least I have, especially when trying to understand the rules related to that concept. What’s more, we also have copy elision, which is a very common optimisation (and even mandatory in several cases in C++17).
Two weeks ago, I showed you a sample that can detect if a function has a given overload. The example revolved around std::from_chars - low-level conversion routine for C++17. In the example, some “heavy” template patterns helped me to write the final code (most notably std::void_t and if constexpr). Maybe there are some other techniques we can use to check if a feature is available or not?
Today is the start day of Summer C++ISO meeting, this time in Cologne, Germany! This is the “feature-complete” meeting for C++20. It’s the last time we’ll see some new elements that are merged into the working draft.
Let’s see what’s already in C++20 and let’s have a look at some smaller, but very handy proposals that might get into the standard.
If you have two function overloads foo(): one is taking const std::string& and the other taking bool. Which one of them will be selected when you call foo("hello world"); ?
Let’s see where such a case might bite us and cause troubles?
Intro Here’s the example once again
void foo(const std::string& in) { std::cout << in << '\n'; } void foo(bool in) { std::cout << "bool: " << in << '\n';} foo("Hello World"); What’s the output?
Last Friday my book got a fresh update! It’s been three months since the previous release, and this time I brought foreword, new book format and some small content changes.
Changes Here are the main changes:
Foreword First of all the book has now a foreword, and it’s written by Herb Sutter!
One of a powerful uses of std::variant is to implement State Machines. Some time ago I showed a simple example, but today we have something bigger. In today’s article by Nikolai Wuttke you’ll see how to leverage std::variant and build a space game!
This article is a guest post from Nikolai Wuttke
If you have a map of strings, like std::map<std::string, int> m; and you want to find some element by m.find("abc"). Do you have to pay the price and construct a std::string object? Can you optimize it?
Let’s have a look at one feature enabled in C++14 that might help optimize such container access.
You’re writing a document about C++, one feature or some cool programming technique. At one point you think that you have to prove that something works and that’s why you need to quote text from the Standard. How to do it?
Intro Referencing the C++ Standard, or maybe a proposal might be quite confusing.
As you may know std::filesystem evolved directly from Boost filesystem library. For a long time, it was available as a Technical Specification and later merged into C++17. Developers who used Boost can ask themselves what the differences between the two libs are. Can the code be easily converted to use std::filesystem?
How would you implement a function that searches for files with a given extension? For example, finding all text files? or *.cpp files? To code that solution you need a way to iterate through directories. Is that possible in C++ out of the box using the standard library? Let’s see some techniques and new elements that C++17 added.