insert_iterator and (x < y)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • romanize
    New Member
    • Jul 2008
    • 5

    insert_iterator and (x < y)

    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?
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    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 <.

    Comment

    • romanize
      New Member
      • Jul 2008
      • 5

      #3
      Originally posted by Laharl
      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 <.
      Thank you for the reply, I should have supplied some code. My specific problem was
      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

      Working...