Commits

Jesús Gómez committed 76927ac

C++ version

  • Participants

Comments (0)

Files changed (1)

+#include <iostream>
+#include <sstream>
+#include <string>
+#include <map>
+
+using namespace std;
+
+template <class T> T f(T);
+template <class T> T f2(T);
+template <class T> T f12(T);
+
+template <class T> T f(T x)
+{
+  return x;
+}
+
+template <class T> T f2(T x)
+{
+  return x*x;
+}
+
+template <class T> T f12(T x)
+{
+  return x/2;
+}
+
+int main(int argc, char **argv)
+{
+  string fun;
+  double x;
+  string ou;
+
+  typedef double (*g)(double);
+  map <string, g> mapfun;
+  mapfun["f"] = f;
+  mapfun["f2"] = f2;
+  mapfun["f12"] = f12;
+
+  stringstream ss(stringstream::in | stringstream::out);
+
+  ss << argv[1] << " " << argv[2];
+  ss >> fun >> x;
+  cout << mapfun[fun](x) << endl;
+}