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.
Thank you for all the comments about the string_view performance! Last week I got a lot of feedback on how to improve the initial string split code.
Have a look at how can we update the code and get some better performance.
Intro Last week I showed a few examples of string_view.
In this text we’ll have a look at a few examples that compare std::string_view against std::string. How much is std::string_view faster than standard std::string operations?
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].
When you read articles or reference pages for std::any, std::optional or std::variant you might notice a few helper types called in_place_* available in constructors.
Why do we need such syntax? Is this more efficient than “standard” construction?
Intro Chinese version here:
C++ std::any、std::variant和std::optional的原位构造(In-Place Construction)_yihuajack的博客-CSDN博客 We have the following in_place helper types:
Writing articles about modern C++ features is a lot of fun, but what’s even better is to see how you use those new things in real world.
Today I’m happy to present a guest post article from JFT who was so kind to describe his project where he uses several C++17 features.
Last week you might have read about a few examples of parallel algorithms. Today I have one more application that combines the ideas from the previous post.
We’ll use parallel algorithms and the standard filesystem to count words in all text files in a given directory.
The Case In my previous post, there were two examples: one with iterating over a directory and counting the files sizes and the next one about counting words in a string.
MSVC (VS 2017 15.7, end of June 2018) is as far as I know the only major compiler/STL implementation that has parallel algorithms. Not everything is done, but you can use a lot of algorithms and apply std::execution::par on them!
Have a look at few examples I managed to run.
With std::optional you can represent some Type or nothing. With std::variant you can wrap several variants into one entity. And C++17 gives us one more wrapper type: std::any that can hold anything in a type-safe way.
The Basics So far in the Standard C++, you had not many options when it comes to holding variable types in a variable.
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.
Show me your code!
I’d like to run a little experiment.
Let’s build a wall of examples of std::optional!
Intro In the last three articles of my C++17 STL series I’ve been discussing how to use std::optional. I can talk and talk… or write and write… but I’m wondering how do you use this wrapper type?
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?
A few months ago I received a quite massive mail package with something that was looking like a brand new C++ book :)
My initial plan was to review it quickly, maybe in one month. But I failed, as learning C++ templates is not that easy :) I needed much more time.
Let’s take a pair of two types <YourType, bool> - what can you do with such composition?
In this article, I’ll describe std:optional - a new helper type added in C++17. It’s a wrapper for your type and a flag that indicates if the value is initialized or not. Let’s see where it can be useful and how you can use it.