How to pass a function signature as input in order to initialize another function in C++?

my question is the following: supposing I have a program, written in C++, which takes a function and gives its integral. In this program I write the function manually, in the source code, and I change its signature every time I want to integrate another function. If now I want to initialize this function in input (for example giving a string), in order to directly initialize it at compiling time, how could I do?

I would be interested in having something like this:

$ ./program
$ Give me the function name: x+3y+4

and now the function is initialized with:

int func() { return x+3y+4; }

Solution 1:

You need this: https://github.com/ArashPartow/exprtk

It is only slightly slower than compiling the expression in native code.

There are also others, you can see most of them here: https://github.com/ArashPartow/math-parser-benchmark-project

(Disclaimer: I am the author of the Node.js bindings: https://github.com/mmomtchev/exprtk.js)