Hi all,
This is a pretty straightforward thing, but I've been bashing my head trying to understand. I'm trying to compare the elements of a vector<complex <double> >
vec with a complex <double>
num to check if num already exists on vec. If it does, it is not added. I tried to use the equal() and algorithm, with no success. Does anybody knows a fast way to do that?
Thank you
EDIT2 : I'm trying to do that for complex numbers as a simplification, as I also need to perform the same operation on a struct:
struct thing{
int i;
int j;
complex <double> pos;
}typedef t_thing;
complex <double> new_num(2.0,2.0);
t_thing will_insert;
will_insert.i = 1;
will_insert.j = 1;
will_insert.pos = new_num;
vector<t_thing> vec_thing;
if(! (find(vec_thing.begin(),vec_thing.end(),will_insert) == vec_thing.end())){
vec_thing.push_back(will_insert);
}else {
cout<<"element already on vec_thing"<<endl;
}
EDIT 3: I've overloaded the operator ==, but find cannot work with that:
: error: no matching function for call to ‘find(__gnu_cxx::__normal_iterator<thing*, std::vector<thing, std::allocator<thing> > >, __gnu_cxx::__normal_iterator<thing*, std::vector<thing, std::allocator<thing> > >, t_thing&)’