関数の返値をパラメータとするテンプレート関数

gcc 3.4だと出来ないと思ってたら出来た。

#include <iostream>
#include <string>
#include <boost/lexical_cast.hpp>

using namespace std;
using namespace boost;

template <class I, class O>
class Foo {
  O (*f_)(I x);
public:
  Foo(O (*f)(I x)): f_(f) {}
  O operator ()(I x) {
    return f_(x);
  }
};

int xstr2int(string str) {
  return lexical_cast<int>(str) * 100;
}

template <class I, class O>
Foo<I, O> mkproxy(O (*f)(I x)) {
  Foo<I, O> foo(f);
  return foo;
}

int main() {
  cout << mkproxy(xstr2int)("100") << endl;
  return 0;
}