boostorg / heap

Boost.Heap
https://boost.org/libs/heap
18 stars 39 forks source link

boost::heap::skew_heap improperly handles rvalue_reference when creating a node. #24

Open kalaxy opened 4 years ago

kalaxy commented 4 years ago

The skew_heap_node constructor taking an rvalue reference makes a copy instead of moving it in. This prevents the use of move only types with skew_heap.

I'm pretty sure that you just need to add std::move to the initializer list construction. E.g.

    skew_heap_node(value_type && v):
        value(std::move(v))
kalaxy commented 4 years ago

Here is an example which triggers the compiler error.

#include <boost/heap/skew_heap.hpp>                                                                                                                                   

struct MoveOnlyInt {                                                                                                                                                  
    MoveOnlyInt(int i) : i(i) {}                                                                                                                                      
    MoveOnlyInt(MoveOnlyInt &&) = default;                                                                                                                            
    MoveOnlyInt& operator=(MoveOnlyInt &&) = default;                                                                                                                 
    friend bool operator<( MoveOnlyInt const &lhs, MoveOnlyInt const &rhs ) {                                                                                         
        return lhs.i < rhs.i;
    }
    int i;
};                                                                                                                                                                    

int main() {
    using PQ = boost::heap::skew_heap<MoveOnlyInt>;                                                                                                                   
    PQ pq;                                                                                                                                                            
    pq.emplace(1);                                                                                                                                                    
}

Switching skew_heap for another like binomial_heap allows it to compile.

timblechmann commented 4 years ago

boost.heap is in maintenance mode. but i'm more than happy to integrate PRs

TimeLikeAlpha commented 1 year ago

Hey Tim, curious what this "maintenance mode" is? Does that mean deprecated?