Thread: std::list<*> sorting

  1. #16
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    >> Exactly. how does one fix that? Like I mentioned, we rewrote the swap function, but we also had to change the operator<

    Yep, thats the way to do it.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  2. #17
    Registered User
    Join Date
    May 2003
    Posts
    148
    >> we rewrote the swap function
    How?
    Try iter_swap
    Code:
    template<class _FwdIt1,
    	class _FwdIt2> inline
    	void iter_swap(_FwdIt1 _Left, _FwdIt2 _Right)
    	{	// swap *_Left and *_Right
    	std::swap(*_Left, *_Right);
    	}

  3. #18
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Cat
    That won't work without ptr_fun() around it; myCompare is not a functor here.

    The other code works much better, but a few changes to make it const-correct (you can get a lot of bizarre error messages if it's not):
    [/code]
    You don't have to add the const modifiers, the template takes care of that for you.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #19
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    >>> You don't have to add the const modifiers, the template takes care of that for you.

    Not necessarily. GCC gave me errors for not having the last const when I used that last week.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting algorithms, worst-case input
    By Leftos in forum C++ Programming
    Replies: 17
    Last Post: 06-15-2009, 01:33 PM
  2. Replies: 26
    Last Post: 06-11-2009, 11:27 AM
  3. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  4. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  5. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM