vendredi 1 avril 2016

define set compare function when set is the element of a vector

I want to define a vector of a set, and the define the set's compare function.

I know how to define the set compare function, like this:

bool isSmall(const std::pair<int, int> &i1, const std::pair<int, int> &i2)
{
    return i1.second < i2.second;
}

std::set, decltype(isSmall)*> set_int(isSmall);

But what if I have a vector, and the vector element is my self-defined set?

std::vector< std::set<std::pair<int, int>, decltype(isSmall)*> > vec_set

this is not corret, since when I insert vec_set[0] another same element like <1,1> (<1,1> has been inserted into vec_set[0]) the program then crash down.

It seems that I should also do something like set_int(isSmall), but How can I do that when I define a vector containg this set like above?

Aucun commentaire:

Enregistrer un commentaire