c++ - std::priority_queue: Custom ordering without defining comparator class -
i want have priority queue custom ordering, lazy am, don't want define comparator class implementing operator().
i compile:
std::priority_queue<int, std::vector<int>, boost::bind(some_function, _1, _2, obj1, obj2)> queue;
where some_function bool returning function taking 4 arguments, first , second being ints of queue, , 2 last ones objects needed calculating ordering (const references).
(error: ‘boost::bind’ cannot appear in constant-expression)
but doesn't compile. more simple
std::priority_queue<int, std::vector<int>, &compare> queue;
won't compile, compare being binary function returning bool.
(error: type/value mismatch @ argument 3 in template parameter list ‘template class std::priority_queue’; expected type, got ‘compare’)
any suggestions?
this work:
std::priority_queue<int, std::vector<int>, boost::function<bool(int,int)> >
then pass in bind expression queue's constructor.
p.s. you're getting compilation errors because you're putting runtime-evaluated expressions typename or constant expression expected.
Comments
Post a Comment