lundi 31 octobre 2016

C++ upper_bound on struct vector with == operator

I have following struct

struct cube
{
    int  index ,l , b , h;
    bool operator<(const cube & c2) const
    {

    if (l == c2.l && b == c2.b && h == c2.h)
        return index < c2.index;
    if (l == c2.l && b == c2.b)
        return h < c2.h;
    if (l == c2.l )
        return b < c2.b;
    return l < c2.l;
    }
    bool operator==(const cube  c2) 
    {
        return index != c2.index && l == c2.l && b == c2.b;
    }
};

Now I want to apply upper_bound on vector of this struct as per condition in == operator.
However , it is still returning me those iterators where index are same

int pos2 = upper_bound(v.begin(),v.end(),v[i]) - v.begin();

i.e v[i].index is equal to v[pos2].index

Aucun commentaire:

Enregistrer un commentaire