I'm trying to sort
std::vector< std::vector< std::string> > perm;
I am attempting to use std::sort from the algorithm header
I called it with
std::sort( perm.begin(), perm.end(), sortPerms);
This is my sort function:
bool sortPerms (const std::vector<std::string> &i, const std::vector<std::string> &j) {
for(unsigned int x = 0; x < i.size(); x++) {
if(i[x] != j[x])
return false;
}
//both are equal
return true;
}
The purpose of sorting is to then call std::unique to obtain a vector with unique values. When I compile with gcc in cygwin, I get no errors but I have repeats, and when I compile with visual studio 2010, I get an error that operator< is not defined. I stepped through and it is attempting to use its own sort function, and not the one that I have defined.
I'm not sure how to fix this, any suggestions?
Other details: It is guaranteed that all vectors will be of same size. It's purpose is a vector of every permutation of an original vector of strings. Each string is a command, and I am looking for all of the different ways these commands can be shuffled. So I need to strip the duplicates.
LEFT < RIGHT, whereLEFTis in your casestd::vector< std::string >. You may need to declare structure with anoperator<inside that would derive fromstd::vector< std::string >and work through it.std::vector<std::string>? Just make a free ("global")operator<like sane people!bool operator<(const std::vector<std::string>& a, const std::vector<std::string>& b);