c++ - Container of sets using non-default comparison predicate -
i create std::map<t1, std::set<t2> >
set
s use non-default comparator. example, if declaring set
on own, declare as:
std::set<int,bool(*)(int,int)> s (fn_pt);
where fn_pt
function pointer. in example, when add new key std::map
, set constructed non-default comparator. such thing possible?
to further complicate things, compiler not support c++11, can accept solution not require c++11; however, if there c++11 way of doing this, interested in seeing well.
since can use functor should able use:
struct compare { bool operator () (int lhs, int rhs) { return lhs - 10 < rhs; } }; int main() { std::map<int, std::set<int, compare> > data; }
each new set created in map default constructed type specified in template parameters.
Comments
Post a Comment