Performance of std::string_view vs std::string from C++17

How much is std::string_view faster than standard std::string operations? Have a look at a few examples where I compare std::string_view against std::string. Intro I was looking for some examples of string_view, and after a while, I got curious about the performance gain we might get. string_view is conceptually only a view of the string: usually implemented as[ptr, length].

READ MORE...

A Wall of Your std::optional Examples

Two weeks ago I asked you for help: I wanted to build a wall of examples of std::optional. I’m very grateful that a lot of you responded and I could move forward with the plan! You’re amazing! Let’s dive in the examples my readers have sent me! A Reminder To remind, I asked for some real-life examples of std::optional.

READ MORE...

Everything You Need to Know About std::variant from C++17

Around the time C++17 was being standardized I saw magical terms like “discriminated union”, “type-safe union” or “sum type” floating around. Later it appeared to mean the same type: “variant”. Let’s see how this brand new std::variant from C++17 works and where it might be useful. The Basics In my experience, I haven’t used unions much.

READ MORE...

Error Handling and std::optional

In my last two posts in the C++17 STL series, I covered how to use std::optional. This wrapper type (also called “vocabulary type”) is handy when you’d like to express that something is ‘nullable’ and might be ‘empty’. For example, you can return std::nullopt to indicate that the code generated an error… but it this the best choice?

READ MORE...

Productive C++ Developer, my recent talk

A few weeks ago I gave another talk at my local C++ user group. We discussed recent “goodies” from C++ and tools that can increase productivity. Intro In my post for the “C++ summary at the end of 2017” I mentioned that we could see a considerable improvement in the area of tooling for the language.

READ MORE...

Deprecating Raw Pointers in C++20

The C++ Standard moves at a fast pace. Probably, not all developers caught up with C++11⁄14 yet and recently we got C++17. Now it’ time to prepare C++20! A few weeks ago The C++ Committee had an official ISO meeting in Jacksonville, FL (12-17 March 2018) where they worked hard on the new specification.

READ MORE...

The C++ Standard Library book - overview & giveaway

Let’s have a quick overview of another book related to Modern C++ and The Standard Library. This time I picked Rainer Grimm’s book the author of the modernescpp blog. Read more if you’d like to win C++ book bundle! :) The book The C++ Standard Library What every professional C++ programmer should know about the C++ standard library

READ MORE...

Simplify code with 'if constexpr' in C++17

Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr! Let’s see how we can use it and replace some std::enable_if code.

READ MORE...