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

Allow passing value_compare by rvalue_ref. #23

Open
kalaxy opened this issue Nov 1, 2019 · 1 comment
Open

Allow passing value_compare by rvalue_ref. #23

kalaxy opened this issue Nov 1, 2019 · 1 comment

Comments

@kalaxy
Copy link

kalaxy commented Nov 1, 2019

Currently the code only supports making a copy of the comparison object. It would be great to support moving comparison objects into place to permit move-only comparison objects and better efficiency of heavy weight comparison objects.

@kalaxy
Copy link
Author

kalaxy commented Nov 1, 2019

Here is a simple piece of code which demonstrates the desire.

#include <boost/heap/skew_heap.hpp>

struct MoveOnlyCmp {
    MoveOnlyCmp() = default;
    MoveOnlyCmp(MoveOnlyCmp &&) = default;
    MoveOnlyCmp& operator=(MoveOnlyCmp &&) = default;

    // Without these there is a compiler error
    //MoveOnlyCmp(MoveOnlyCmp const&) = default;
    //MoveOnlyCmp& operator=(MoveOnlyCmp const&) = default;

    bool operator()( int lhs, int rhs ) const {
        return lhs < rhs;
    }
};

int main() {
    using PQ = boost::heap::skew_heap<int, boost::heap::compare<MoveOnlyCmp>>;

    MoveOnlyCmp cmp{};

    PQ pq( std::move(cmp) );
    pq.push(1);
    pq.pop();
}

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

1 participant