1

Using fibonacci_heap results in a compilation error:

struct Less: public binary_function<Node*, Node*, bool>
{
    bool operator()(const Node*& __x,  Node*& __y) const
        { return __x->time < __y->time; }

};

boost::fibonacci_heap<Node*, Less >*    m_heap;

then

Less* ls = new Less;
m_heap = new boost::fibonacci_heap<Node*, Less >(1000, (*ls));

Any attempt to run m_heap->push(n) results in

no match for call to ‘(TimeSync::Less) (TimeSync::Node* const&, TimeSync::Node*&)’
UnmanagedUtils/Trading/Simulation/TimeSync.h:50: note: candidates are: bool TimeSync::Less::operator()(const TimeSync::Node*&, TimeSync::Node*&) const
/usr/local/include/boost-1_35/boost/property_map.hpp: In function ‘Reference boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::identity_property_map, Reference = unsigned int, K = TimeSync::Node*]’:
Asciiom
  • 9,867
  • 7
  • 38
  • 57
R_N
  • 111
  • 9
  • Is there some reason you're doing weird things with memory? i.e. allocating data on the heap without visible reason. – Wug Sep 19 '12 at 12:42
  • I need the Less object to be alive after the scope of this function, but anyway it does not matter, declaring Less as local variable results same – R_N Sep 19 '12 at 12:46
  • Also, the method signature of the method the call expects indicates that a const modifier is not in the right place. Try changing your signature to: `bool operator()(Node* const& __x, Node*& __y) const` – Wug Sep 19 '12 at 12:48
  • If the only reason you need it to be alive is so the heap can continue to own it, it already will, since you pass it a copy. – Wug Sep 19 '12 at 12:50
  • did it before:), does not help, not the issue here (regarding the const qualifier) – R_N Sep 19 '12 at 12:50

1 Answers1

2

Change the signature to operator()(Node * const &, Node * const &) const.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • The `operator()` of your predicate has to take the arguments by const-reference (or by value); that's all. Your original code had non-const references, which can't be bound to by the internal algorithms of the data structure, which presumably pass elements as constant references. – Kerrek SB Sep 19 '12 at 12:56
  • @RomanNassimov: That said, I would personally just write the operator as `operator()(Node *, Node *) const`. There's no benefit here in passing the pointers by const-reference, since you know that they're very small types. – Kerrek SB Sep 19 '12 at 13:03