9 cost_func::cost_func(const char* param)
11 std::istringstream paramstream(param);
13 while (std::getline(paramstream, token, ',')) {
14 std::istringstream str(token);
16 if ((str >> f) && str.eof())
19 throw std::invalid_argument("cost_func(): "
20 "cannot parse \"" + token + "\"");
23 throw std::invalid_argument("cost_func(): no factor");
26 cost_func::~cost_func()
30 double cost_func::operator()(double amount) const
32 return std::accumulate(++factors.begin(), factors.end(), factors.front(),
33 [&amount](double a, double b) {
34 return amount * a + b;
38 std::string cost_func::to_string()
40 std::ostringstream oss;
41 std::copy(factors.begin(), --factors.end(),
42 std::ostream_iterator<double>(oss, ", "));
43 oss << factors.back();