Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kalaxy opened this issue Nov 1, 2019 · 3 comments

Comments

@kalaxy
Copy link

kalaxy commented Nov 1, 2019

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
Copy link
Author

kalaxy commented Nov 1, 2019

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
Copy link
Collaborator

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

@TimeLikeAlpha
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants