If you want to count how many elements in vec2
is greater than the i'th
element in vec1
then you are doing it correct and just have to capture val
in the lambda
for(int i = 0; i < vec1.size(); i++)
{
int val = vec1[i];
auto res = count_if(begin(vec2),end(vec2), [val](int x) { return (x > val); });
}
but if you want to compare each element in vec2
with the corresponding element in vec1
you have to do it manually.
int count = 0;
//here the sizes of vec1 and vec2 must be equal
for (auto it1 = begin(vec1), it2 = begin(vec2); it1 != end(vec1); ++it1, ++it2) {
if (*it2 > *it1)
++count;
}
EDIT:
As @Jarod42 commented. It is possible to use an algorithm for the second case
auto res = std::transform_reduce(begin(vec2), end(vec2), begin(vec1), 0,
std::plus<>(), std::greater<>());