| | | | | |

Generic Algorithms and Function Objects

  • Function classes may be passed to generic algorithm as template parameter
  • Commonly used to pass predicates such as LessThan
  • Also used for other function classes
template <class I, class F>
F g_for_each (I beg, I end, F f)
{
  for ( ; beg!= end; ++beg)
    f(*beg);
  return f;
}
    // usage:
    List<char> L;
    MakeUpperCase muc;
    g_for_each (L.Begin(), L.End(), muc);
    // converts every element of L to upper case
    

| | Top of Page | 8. Generic Algorithms - 6 of 12