I'd like to find the unique number in std::vector, but I see an error that I don't understand. Can someone take a look, and explain me what is going wrong? Optionally if you have a better solutions, please, share.
#include <iostream>
#include <vector>
#include <algorithm>
float find_uniq(const std::vector<float> &v)
{
if(v[0] == v[1]) {
auto it = std::find_if_not(v.begin(), v.end(), v[0]);
return *it; }
else if(v[0] == v[2]) {
auto it = std::find_if_not(v.begin(), v.end(), v[0]);
return *it; }
else if(v[1] == v[2]) {
auto it = std::find_if_not(v.begin(), v.end(), v[1]);
return *it; }
};
int main()
{
std::vector<float> m = {4, 4, 3, 4, 4};
std::cout<< find_uniq(m);
return 0;
}
Here is an error:
error: expression cannot be used as a function
{ return !bool(_M_pred(*__it)); }