Docs of boost::math::statistics::mode::mode() suggests that data will be sorted if random access iterators are passed:
Nota bene: The input data must be sorted in order to pass a forward iterator. If data is not sorted random access iterators are required for a call to std::sort.
Both examples in the docs have non-sorted data, but with modes adjacent to each other ( {1, 3, 2, 2, 5, 4}, {2, 2, 3, 1, 5, 4, 4}) .
In any case, for std::vector<int>{3,2,1,2}, mode returns the entire data as its result (in boost 1.90 on Ubuntu 26.04):
#include <boost/math/statistics/univariate_statistics.hpp>
#include <algorithm>
#include <print>
int main()
{ namespace bms = boost::math::statistics;
std::vector<int> v = {3,2,1,2};
auto mode = bms::mode(v);
std::ranges::sort(v);
auto mode2 = bms::mode(v);
std::println("{}",mode2); //prints [2]
std::println("{}",mode); //prints [3, 2, 1, 2]
}
Docs of
boost::math::statistics::mode::mode()suggests that data will be sorted if random access iterators are passed:Nota bene: The input data must be sorted in order to pass a forward iterator. If data is not sorted random access iterators are required for a call to std::sort.
Both examples in the docs have non-sorted data, but with modes adjacent to each other ( {1, 3, 2, 2, 5, 4}, {2, 2, 3, 1, 5, 4, 4}) .
In any case, for
std::vector<int>{3,2,1,2}, mode returns the entire data as its result (in boost 1.90 on Ubuntu 26.04):