#include#include #include #include struct person { std::string name; int age; double height; }; BOOST_PFR_DECLARE_TUPLE_SIZE(person,name,age,height) int main() { person p = {"John", 30, 1.75}; // open file std::ofstream outfile("data.txt"); // save person object to file boost::pfr::save(outfile, p); // close file outfile.close(); // reopen file std::ifstream infile("data.txt"); // read person object from file person q; boost::pfr::load(infile, q); // close file infile.close(); // print loaded object std::cout << boost::pfr::get<0>(q) << " " << boost::pfr::get<1>(q) << " " << boost::pfr::get<2>(q) << std::endl; return 0; }
#includeIn this example, a lambda function `add` that adds two integers is defined. The `persistent_function` class is used to create a persistent version of the `add` function. The persistent function is successfully called with two integer literals and the result is printed to the console. The Boost C++ Libraries package is used to provide the `persistent_function` class.#include int main() { // define function object auto add = [] (int a, int b) { return a + b; }; // make function object persistent boost::persistent_function add_p(add); // call persistent function int result = add_p(2, 3); // print result std::cout << result << std::endl; return 0; }