
-----------------------------------
wtd
Tue Apr 06, 2004 11:09 pm

[C++] Function Objects
-----------------------------------
C++ templates and operator overloading allow for a lot of interesting programming techniques to be implemented.  One of the interesting ones is creating functions that can be passed around like objects.

Normally, in C and C++, functions are just places in memory where certain chunks of code begin.  They aren't first-class things that can be passed to other functions.  So, if functions can't be made to behave like objects, why don't we make objects behave like functions?

We can overload the () operator like so:

#include 
#include 

class Foo {
   public:
      void operator()(std::string input) {
         std::cout 