Function Objects -- 3
- Why function objects instead of functions?
- Abstraction -- template parameters
- Versatility -- "smart" functions
- Performance -- better info for compiler leads to better optimization
- Most common use in STL: Predicate Classes
- Function classes that are boolean valued
- E.g., LessThan<T>, GreaterThan<T>
- Other examples:
- Hash objects
- Wrapper for any function to be applied by generic algorithms (such as makeuppercase
-- a wrapper for toupper())
- IO manipulators
- Smart functions (have data, will use)
|