c++ - How use std::multiset with multiple comparator function? -


good afternoon, have c++ class range implements operator < use std::multiset<range> ranges_type.

since multiset constructor don't specify a custom comparator functor, uses std::less operator <.

however, need use second comparator functor std::multiset ranges_type. specifically, specify second comparator: std::multiset<range, pointercompare> struct pointercompare looks :

struct pointercompare{    bool operator()(const range& a, const range& b) const {          return (a.mptr == b.mptr)    } 

is possible use std:multiset multiple comparator functions or there workaround? thank you

the class range looks this:

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; }; // class range  

sounds you'd better if used boost::multiindex rather trying force several different comparator functions onto std::multiset. have bunch of different container types (see here.) in particular i'd @ ordered_indices versions.


Comments