c++ - How to pass compare object or function to class function -
c++ - How to pass compare object or function to class function -
i'm going implement info structures, segment tree, heap(priority queue). however, want write 1 time , can pass compare object or compare function can set max-heap or min-heap (in past, have write 2 classes).
the question how pass compare object or compare function class function
this want do
struct heap{ sometype comp; void init(sometype f){ comp = f; } ... } and when want compare i'll utilize
comp(a, b); // << want homecoming bool how can set compare object greater<int> or less<pair<int, int> > struct ?
and if want write compare object or function, how can it.
sorry bad english language give thanks you.
make heap template, next :
template<typename sometype, typename compartor = std::less<sometype> > struct heap { // .... }; then can :
heap<int, std::greater<int> > h; otherwise can have std::function<bool(heap const& lhs , heap const& rhs )> func ; within heap , take func argument in fellow member function outside world.
c++ class object struct compare
Comments
Post a Comment