Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double func1(std::map<std::string, double> arr)
- {
- dydt = arr["one"] * 3.0 - arr["two"];
- return dydt;
- }
- double func2(std::map<std::string, double> arr)
- {
- dydt = 1 / arr["three"] + 3.0 * arr["two"];
- return dydt;
- }
- double solver(std::vector<std::function<double(std::map<char, double>) &funcs, std::map<std::string, double> inputs)
- {
- double res;
- std::vector<double> data;
- for (int i = 0; i < funcs.size(); i++)
- {
- // - The ODE solver is not shown in this example,
- // but it highlights the general intent
- res = funcs[i](inputs);
- data.push_back(res);
- }
- return data;
- }
- int main()
- {
- std::map<std::string, double> inputs;
- inputs["one"] = 1.0;
- inputs["two"] = 2.0;
- inputs["three"] = 3.0;
- inputs["four"] = 4.0;
- // The line of code below does not work
- std::vector<std::function<double(std::map<char, double>)>> funcs = {func1, func2};
- std::vector<double> dat;
- // - Due to the fact that the array of funcs does not work,
- // this function call also does not work
- dat = solver(funcs, inputs);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement