Increased Complexity of C++20 Range Algorithms Declarations - Is It Worth?

With the addition of Ranges and Concepts in C++20, our good old algorithm interfaces got super long “rangified” versions. For example, copy is now 4 lines long… and it’s just the declaration! template <ranges::input_range R, std::weakly_incrementable O> requires std::indirectly_copyable<ranges::iterator_t<R>, O> constexpr ranges::copy_result<ranges::borrowed_iterator_t<R>, O> copy(R&& r, O result); How to decipher such a long declaration?

READ MORE...

Parallel STL And Filesystem: Files Word Count Example

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.

READ MORE...

C++17 in details: Parallel Algorithms

Writing multithreaded code is hard. You want to utilize all of the machine’s processing power, keep code simple and avoid data races at the same time. Let’s see how C++17 can make writing parallel code a bit easier. Intro With C++11⁄14 we’ve finally got threading into the standard library. You can now create std::thread and not just depend on third party libraries or a system API.

READ MORE...

Top 5 Beautiful C++ std Algorithms Examples

Some time ago I’ve seen an inspiring talk from CppCon 2013: “C++ Seasoning” by Sean Parent. One of the main points of this presentation was not to use raw loops. Instead, prefer to use existing algorithms or write functions that ‘wraps’ such loops. I was curious about this idea and searched for nice code examples.

READ MORE...