Assumption here is that I am receiving many values and I do not want to store them in the vector. So I would like to use something like boost accumulators. But in docs I can not find something like the logic I want.
Is there a way for me to have accumulator so that when called with
5, 10 , 12 , 15 , 27 it will output 2(minimal difference between two adjacent values, 10 and 12).
I know I can keep the last variable by myself and just use the acc(current-last) with tag::min, but I prefer to leave that to library if possible.
Not with the accumulators that are part of Boost, but you can write your own.
The accumulator itself will look something like this. Note that this version only handles an increasing sequence of values correctly, but does not required an initial sample. If you have different requirements you can tune this.
Putting it into the
boost::accumulators::implnamespace is recommended in the documentation.Next, we need a tag
and an extractor
You can then use it like any of the accumulators provided by boost. You can check out an interactive version on compiler explorer.