17 Smaller but Handy C++17 Features

When you see an article about new C++ features, most of the time you’ll see a description of major elements. Looking at C++17, there are a lot of posts (including articles from this blog) about structured bindings, filesystem, parallel algorithms, if constexpr, std::optional, std::variant… and other prominent C++17 additions.

READ MORE...

Moved or Not Moved - That Is the Question!

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).

READ MORE...

Five Awesome C++ Papers for Cologne ISO Meeting

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.

READ MORE...

How To Detect Function Overloads in C++17, std::from_chars Example

The problem: a library function offers several overloads, but depending on the implementation/compiler, some of the overloads are not available. How to check the existence of an overload? And how to provide a safe fallback? In this article, I’ll show you a background “theory” and one case - std::from_chars that exposes full support for numbers or only integer support (in GCC, Clang).

READ MORE...

[Quick Case] Surprising Conversions of const char* to bool

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?

READ MORE...

Converting from Boost to std::filesystem

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?

READ MORE...

Improving Print Logging with Line Pos Info & Modern C++

No matter how proficient you are, I think, you might still use one of the primary methods of debugging: trace values using printf, TRACE, outputDebugString, etc… and then scan the output while debugging. Adding information about the line number and the file where the log message comes from is a very efficient method that might save you a lot of time.

READ MORE...