Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting deque of boost tuples

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);
  }
}
like image 366
the_e Avatar asked Nov 13 '22 02:11

the_e


1 Answers

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);
  }
};
like image 168
ildjarn Avatar answered Dec 19 '22 12:12

ildjarn