Let's say we have a std::vector of circles, and we want to calculate the sum of all circle areas. The algorithm we will use is std::transform() to transform the vector of circles to a vector of areas, and then std::reduce() to summarize the areas.
The Circle struct is defined as shown below, where x and y denotes the position, and r denotes the radius.
struct Circle { float x, y, r; };
We will also use this function to generate a std::vector of random circles:
auto make_circles(size_t n) { auto cs = std::vector<Circle>{}; cs.resize(n); std::generate(cs.begin(), cs.end(), [](){ auto x = float(std::rand()); auto y = float(std::rand()); auto r = std::abs(float(std::rand())); ... |