SHARE
TWEET

Untitled

a guest Jun 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double func1(std::map<std::string, double> arr)
  2. {
  3.     dydt = arr["one"] * 3.0 - arr["two"];
  4.     return dydt;
  5. }
  6.  
  7. double func2(std::map<std::string, double> arr)
  8. {
  9.     dydt = 1 / arr["three"] + 3.0 * arr["two"];
  10.     return dydt;
  11. }
  12.  
  13. double solver(std::vector<std::function<double(std::map<char, double>) &funcs, std::map<std::string, double> inputs)
  14. {
  15.     double res;
  16.     std::vector<double> data;
  17.     for (int i = 0; i < funcs.size(); i++)
  18.     {
  19.         // - The ODE solver is not shown in this example,
  20.         //   but it highlights the general intent
  21.         res = funcs[i](inputs);
  22.         data.push_back(res);
  23.     }
  24.     return data;
  25. }
  26.  
  27. int main()
  28. {
  29.     std::map<std::string, double> inputs;
  30.     inputs["one"] = 1.0;
  31.     inputs["two"] = 2.0;
  32.     inputs["three"] = 3.0;
  33.     inputs["four"] = 4.0;
  34.  
  35.     // The line of code below does not work
  36.     std::vector<std::function<double(std::map<char, double>)>> funcs = {func1, func2};
  37.     std::vector<double> dat;
  38.  
  39.     // - Due to the fact that the array of funcs does not work,
  40.     //  this function call also does not work
  41.     dat = solver(funcs, inputs);
  42.     return 0;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top