jeudi 28 mai 2015

Saving lambda expression or function to a binary file

Basically, I have a function which takes some arguments, one of which is a lambda expression or function:

foo(int i, int j, std::function<double(double)> func);

I'd like to be able to save these arguments to a binary file, so something like this:

std::ofstream os("test.bin", std::ios::out | std::ios::binary);
os.write(reinterpret_cast<const char*>(&i), std::streamsize(sizeof(int)));
os.write(reinterpret_cast<const char*>(&j), std::streamsize(sizeof(int)));
// What to do for func?

Is there a way to do this? This save function would be called before foo, so I'd know whether or not the input is an actual function or lambda (if that helps). It doesn't need to be portable between systems- I'd just like to be able to save these arguments to disk so I can load them up and rerun the function using the same parameters later.

Aucun commentaire:

Enregistrer un commentaire