You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C++20 includes updated versions of the many algorithms in the <algorithm> header. This header supplements these with updated versions of
other algorithms from the <numeric> header.
If you're using C++20 ranges (or NanoRange -- see below)
then you can drop the numeric_ranges.hpp header into your project and use it
as a modern replacement for <numeric> until such time as C++23 comes along.
If your standard library provides an implementation of C++20 ranges, you can
just copy numeric_ranges.hpp into your project and use it as an alternative to the <numeric> header.
The rest of this respository contains testing machinery and is not required for use.
numeric_ranges.hpp is also compatible with NanoRange.
To use it, define the symbol TCB_NUMERIC_RANGES_USE_NANORANGE
before #include-ing this header, for example
Note that in this implementation, reduce and transform_reduce always perform their operations in order and so are equivalent to accumulate and inner_product respectively.
Caveats
Unlike the other algorithms in std::ranges (and the eventual C++23 version of
<numeric>) the implementations in this library are unconstrained.
This means that it's possible to get horrible, C++98-style template error messages when things
go wrong. It's also possible that in rare cases, code you write today with this library may fail
constraint checks when they are added in future.
Licence
This library is provided under the terms of the Boost licence.
Acknowledgements
Thanks to Eric Niebler for writing the Range-V3 tests for all these algorithms,
which I have lovingly "borrowed".
Thanks to Phil Nash et al for the fantastic Catch2 testing framework.