Book Image

The Modern C++ Challenge

Book Image

The Modern C++ Challenge

Overview of this book

C++ is one of the most widely-used programming languages and has applications in a variety of fields, such as gaming, GUI programming, and operating systems, to name a few. Through the years, C++ has evolved into (and remains) one of the top choices for software developers worldwide. This book will show you some notable C++ features and how to implement them to meet your application needs. Each problem is unique and doesn't just test your knowledge of the language; it tests your ability to think out of the box and come up with the best solutions. With varying levels of difficulty, you'll be faced with a wide variety of challenges. And in case you're stumped, you don't have to worry: we've got the best solutions to the problems in the book. So are you up for the challenge?
Table of Contents (15 chapters)

Solutions

61. Parallel transform algorithm

The general-purpose function std::transform() applies a given function to a range and stores the result in another (or the same) range. The requirement for this problem is implementing a parallel version of such a function. A general-purpose one would take iterators as arguments to define the first and one-past-last element of the range. Because the unary function is applied in the same manner to all the elements of the range, it is fairly simple to parallelize the operation. For this task, we will be using threads. Since it is not specified how many threads should be running at the same time, we could use std::thread::hardware_concurrency(). This function returns a hint for the number...