Topical Information

This program should help clarify to you the use of templates and function objects.

Program Information

Modify either your template'd sort from class or the one associated with the template'd Set to accept a function argument which it should use to compare the elements of the array. This function should return true when the items passed are 'out of order' (left to right) in the argument list. (i.e. For an ascending sort, the function would return the result of a > operation. For a descending sort, the function would return the result of a < operation. A class with complicated data might require comparing several data members in order to come up with a determination of 'out of order'.) All other aspects of the sort are as before.

Show your sort's power by sorting arrays of

all in one test application. (Hint: It might prove advantageous to overload your templated swap for Cstrings ...of a particular length.)

Also pass comparison function (object)s which result in both ascending and descending order of each of the arrays' elements.

Thought Provoking Questions

  1. What things might cause your new sort template to fail to instantiate?

  2. Where should the overloaded swap form go? (In the library or the main application?) If in the library, should it be in the header with the swap template or in the implementation file? Does it matter to the compiler where it is? Why/Why not?

  3. Did you need to make any changes to your original swap template?

  4. Which comparisons did you write as plain functions? Function objects? Were any of them templated? Could/Should they have been? (Hint: you should use at least one plain function and one function object class to show you can do both.)

This assignment is (Level 2).