As usually, C++ needs good books and up-to-date learning resources. In this review, I’d like to present a book that should significantly enhance your knowledge of Modern C++, including C++17.
Let’s see what’s inside.
Disclaimer: I asked the author and got a print copy for the review.
The book
std::visit is a powerful utility that allows you to call a function over a currently active type in std::variant. It does some magic to select the proper overload, and what’s more, it can support many variants at once.
Let’s have a look at a few examples of how to use this functionality.
I’m happy to announce that just a few days ago I updated the book! “C++17 In Detail” grew by 7 pages (up to 219), includes a few new examples, new feature descriptions and lots of “bug fixes”.
See what’s inside.
The Changes Here’s the short version of the release notes:
Searchers from C++17 are a new way to perform efficient pattern lookups. The new standard offers three searchers: default_searcher , boyer_moore_searcher and boyer_moore_horspool_searcher. The last two implements algorithms that require some additional preprocessing for the input pattern. Is there a chance to separate preprocessing time from the search time?
With C++17 you can now use more sophisticated algorithms for pattern searches! Now, you’ll have more control and a promising performance boost for many use cases.
Intro The naive approach of finding a pattern in a string is O(nm) (where n is the length of the whole string, m is the length of the pattern).
I’m happy to present my first ebook on C++!
Here’s the short story and the description of what you can find inside.
The Story At the beginning of 2017, I decided to make a super long, collaborative, post about all the new things that are coming with C++17. At that time we had quite “stable” drafts, so most of the new features were already known.
How do you initialise a string member in the constructor? By using const string&, string value and move, string_view or maybe something else?
Let’s have a look at possible options.
Intro Below there’s a simple class with one string member. We’d like to initialise it.
For example:
class UserName { std::string mName; public: UserName(const std::string& str) : mName(str) { } }; As you can see a constructor is taking const std::string& str.
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.
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].
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 We have the following in_place helper types:
std::in_place_t type and a global value std::in_place - used for std::optional std::in_place_type_t type and a global value std::in_place_type - used for std::variant and std::any std::in_place_index_t type and a global value std::in_place_index - used for std::variant The helpers are used to efficiently initialise objects “in-place” - without additional temporary copy or move operations.
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.