I am trying to combine std::accumulate
with std::min
. Something like this (won\'t compile):
vector V{2,1,3};
cout <&l
The problem is that there are several overloads of the min function:
template <class T> const T& min(const T& a, const T& b);
template <class T, class BinaryPredicate>
const T& min(const T& a, const T& b, BinaryPredicate comp);
Therefore, your code is ambiguous, the compiler does not know which overload to choose. You can state which one you want by using an intermediate function pointer:
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> V{2,1,3};
int const & (*min) (int const &, int const &) = std::min<int>;
std::cout << std::accumulate(V.begin() + 1, V.end(), V.front(), min);
}