Hi. Is it true - and if so, then why - does the STL (i have some some g++ 4.2 under ubuntu) insert_iterator try to use operator< instead of the Compare object specified in the container, e.g. std::set?
insert_iterator and (x < y)
Collapse
X
-
If you want STL iterators to use a comparator other than operator<, you need to pass the comparator function to the constructor of the set or map or the algorithmic function in question (third parameter). http://www.cplusplus.com/reference/stl/set/set.html may be useful.
The compare third argument to, say, sort(iterator, iterator, comparator=less <Key>); simply defaults to <. -
Originally posted by LaharlIf you want STL iterators to use a comparator other than operator<, you need to pass the comparator function to the constructor of the set or map or the algorithmic function in question (third parameter). http://www.cplusplus.com/reference/stl/set/set.html may be useful.
The compare third argument to, say, sort(iterator, iterator, comparator=less <Key>); simply defaults to <.
set_intersectio n(a.begin(), a.end(), b.begin(), b.end(), std::inserter(c , c.begin()));
where
a,b,c are of type std::set<Key,Cu stomCompare>.
Apparently, std::inserter does not try to use CustomCompare.
I have implemented an operator< into the definition of Key, which does the job, but -
Can I not supply CustomCompare to std::insert_ite rator somehow?
thanks.
EDIT:
alright, you supply it to set_intersect(. ..);Comment
Comment