Domanda

Not sure if I have a simple typo somewhere, but I'm running into issues in sorting a deque of tuples.

So, my deque looks like this:

std::deque<boost::tuple<unsigned int, unsigned int> > messages;

And then I have my call to sort:

sort(messages.begin(), messages.end(), msg_sort_criteria);

And my sorting function:

bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, boost::tuple<unsigned int, unsigned int> rhs)
{
  return boost::get<1>(lhs) < boost::get<1>(rhs);
}

What happens is that I get errors in stl_heap.h and stl_algo.h. For instance,

Called object type '<bound member function type>' is not a function or function parameter.


Edit:

For clarification, this is all taking place within private members of a class.

class Messages::MessageImpl{
private:
  std::deque<boost::tuple<unsigned int, unsigned int> > messages;

  bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, boost::tuple<unsigned int, unsigned int> rhs)
  {
    return boost::get<1>(lhs) < boost::get<1>(rhs);
  }

  void fn()
  {
    sort(msg_queue_.begin(), msg_queue_.end(), msg_sort_criteria);
  }
}
È stato utile?

Soluzione

Mostly reposting from comment.

Change your implementation to:

class Messages::MessageImpl{
private:
  std::deque<boost::tuple<unsigned int, unsigned int> > messages;

  static bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs,
                                boost::tuple<unsigned int, unsigned int> rhs)
  {
    return boost::get<1>(lhs) < boost::get<1>(rhs);
  }

  void fn()
  {
    sort(msg_queue_.begin(), msg_queue_.end(), &MessageImpl::msg_sort_criteria);
  }
};
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top