I've come across with the following problem. I have a std::vector< std::pair<int, Move> > x
of type std::pair<int, Move>
where Move
is an arbitrary object not having any comparison operator defined, for example < > !+ == <= >=
and so on.
The main reason why I paired the Move
objects with a integer values is that the Move
objects should have a number describing their priority for some purpose. The main intention is to sort the vector thus sorting Move
objects using their respective integer values.
Real problem begins when I want to sort these pairs in the vector using std::sort
function. Initially I thought that only first element of std::pair
mattered for comparison, however, it turned out to be that both objects need comparison operations defined for them for the program to be successfully compiled.
Since I did not want to modify original Move
class, I wrote a Wrapper
class that was supposed to wrap std::pair<int, Move>
and have a comparison operation defined on it so that a std::vector< Wrapper < std::pair<int, Move> > > x;
could be sorted without having to modify Move
class. The logic here is that vector
is provided with a class that has <
operation defined.
I have used the below wrapper class:
template <typename T>
struct Wrapper{
Wrapper(const T & pair): pair_mem(pair)
bool operator(const T & other_pair) const{
return this->pair_mem.first < other_pair.first;
}
T pair_mem;
};
Well, as you may have already guessed the approach above did not work and I had to go through bunch of compiler errors. At last, I tried adding < operator
to the Move class and even after that I was not able to compile the program.
Below is the error I think is the most important.
: note: this candidate was rejected because mismatch in count of arguments
struct Wraper{
^
: note: this candidate was rejected because mismatch in count of arguments
Wraper(const std::pair<int, Move> & move){
I am using mpiCC
as the compiler
UPDATE
I did change T
to Wrapper
as one of the answers suggested, but the problem is not solved. Here is the screenshot from the compiler,