[Bug libstdc++/67085] priority queue should not copy comparators when calling push_heap and pop_heap

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Aug 1 00:45:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67085

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Calcutt from comment #1)
>  typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
>  std::push_heap<_Sequence::iterator,_Comp_ref>(c.begin(), c.end(), comp);

Apart from the fact that this is not valid in C++03, this is not how push_heap
is meant to be used. It is defined to take its arguments by value, not by
reference, so it's expected to be cheap to copy the functor, which is common to
all STL algorithms. I see no reason to change that just for priority_queue
(although if we were to do it I'd use std::ref not std::add_lvalue_reference).



More information about the Gcc-bugs mailing list