#include using namespace std; template struct FFIResult { T ok; char *error; }; template FFIResult try_execute(F f, T v) { try { return {f(), nullptr}; } catch (std::exception &e) { return {v, (char *)(e.what())}; } };