Good afternoon, I have a C ++ Range class that implements operator < to use std::multiset<Range> ranges_type .
Since the multiset constructor does not specify an arbitrary comparator functor, it uses std::less operator < .
However, I need to use the second comparator functor for std::multiset ranges_type . In particular, I would indicate the second comparator: std::multiset<Range, PointerCompare> where the struct PointerCompare looks like this:
struct PointerCompare{ bool operator()(const Range& a, const Range& b) const { return (a.mPtr == b.mPtr) }
Is it possible to use std:multiset with several comparator functions or is there a workaround? thank you
The Range class is as follows:
class Range { public: explicit Range(int item){ mLow = item; mHigh = item; mPtr = 0; } Range(int low, int high, char* ptr = 0,char* mapptr = 0){ mLow = low; mHigh = high; mPtr = ptr; } Range(void){ mLow = 0; mHigh = 0; mPtr = 0; } Range(const Range& r): mLow(r.mLow), mHigh(r.mHigh), mPtr(r.mPtr) { } bool operator==(const Range& rhs) const{ return (mLow <= rhs.mLow && mHigh >= rhs.mHigh); } bool operator<(const Range& rhs) const{ return mHigh < rhs.mHigh; } int low() const { return mLow; } int high() const { return mHigh; } char* getPtr() const { return mPtr; } private: int mLow; int mHigh; char* mPtr; };
Frank source share