Fluent::Programmer

    Home Blog About
  • Home
  • Blog
  • About

What is new in <numeric> library in C++17? 👋

  • Fluent Programmer
  •   3 min read

Quick summary ↬  The library in C++ STL C++17 introduces several new algorithms and overloads, including the following:

Numeric library C++17 addition

  1. std::transform_reduce: This algorithm applies a binary operation to elements of a range that have been transformed by a unary operation, and returns the result of the accumulation of the transformed elements using the binary operation.

  2. std::exclusive_scan: This algorithm performs an exclusive prefix sum on a range of elements, where each element is the sum of the previous elements in the range, excluding the element itself.

  3. std::inclusive_scan: This algorithm performs an inclusive prefix sum on a range of elements, where each element is the sum of the previous elements in the range, including the element itself.

  4. std::sample: This algorithm randomly samples a specified number of elements from a range.

  5. Overloads of std::reduce: The std::reduce algorithm has several new overloads that allow the user to specify execution policies, as well as a binary operation and a combination function that can be used to improve performance for certain types of calculations.

  6. Overloads of std::inner_product: The std::inner_product algorithm has several new overloads that allow the user to specify execution policies, as well as a binary operation and a combination function that can be used to improve performance for certain types of calculations.

  7. Overloads of std::transform_exclusive_scan and std::transform_inclusive_scan: These algorithms combine the functionality of std::transform, std::exclusive_scan, and std::inclusive_scan into a single operation.

  8. Execution policies: Many algorithms in the library now have overloads that take an execution policy as the first argument. Execution policies allow the user to specify how the algorithm should be executed, such as whether to execute it in parallel or sequentially.

  9. std::gcd and std::lcm: These functions calculate the greatest common divisor and least common multiple of two integers, respectively.

  10. std::midpoint: This function calculates the midpoint of two values, and is useful for avoiding overflow or underflow when calculating the average of two values. This is C++20 addition.

  11. Overloads of std::accumulate: The std::accumulate algorithm has several new overloads that allow the user to specify execution policies, as well as a binary operation and an initial value that can be used to improve performance for certain types of calculations.

  12. Overloads of std::partial_sum: The std::partial_sum algorithm has several new overloads that allow the user to specify execution policies, as well as a binary operation that can be used to improve performance for certain types of calculations.

  13. Overloads of std::adjacent_difference: The std::adjacent_difference algorithm has several new overloads that allow the user to specify execution policies, as well as a binary operation that can be used to improve performance for certain types of calculations.

These new additions to the library provide additional functionality and improved performance for a wide variety of algorithms and use cases.

You may like this

About The Author

Fluentprogrammer doesn't need coffee to program. They run on pure caffeine and lines of code.

Email Newsletter

Table of Contents

  • Numeric library C++17 addition
  • You may like this
  • C++
  • Beautiful code series

Unhealthy love with dark corners of C++

Founded by an engineer to help engineers. 2021–2023.

  • About us
  • Privacy policy