functors/functordemo.cpp

The following code example is taken from the book
C++ Templates - The Complete Guide
by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley, 2002
© Copyright David Vandevoorde and Nicolai M. Josuttis 2002


#include <iostream>
#include <string>
#include <typeinfo>
#include "funcptr.hpp"

double seven() 
{
    return 7.0;
}

std::string more() 
{
    return std::string("more");
}

template <typename FunctorT>
void demo (FunctorT func) 
{
    std::cout << "Functor returns type "
              << typeid(typename FunctorT::ReturnT).name() << '\n'
              << "Functor returns value "
              << func() << '\n';
}

int main() 
{
    demo(func_ptr(seven));
    demo(func_ptr(more));
}