10 cost_func::cost_func(const char* param)
12 std::istringstream paramstream(param);
14 while (std::getline(paramstream, token, ',')) {
15 std::istringstream str(token);
17 if ((str >> f) && str.eof())
20 throw std::invalid_argument("cost_func(): "
21 "cannot parse \"" + token + "\"");
24 throw std::invalid_argument("cost_func(): no factor");
27 cost_func::~cost_func()
31 double cost_func::operator()(double amount) const
33 using std::placeholders::_1;
34 using std::placeholders::_2;
35 return std::accumulate(++factors.begin(), factors.end(), factors.front(),
36 std::bind(std::plus<double>(),
37 std::bind(std::multiplies<double>(),
41 std::string cost_func::to_string()
43 std::ostringstream oss;
44 std::copy(factors.begin(), --factors.end(),
45 std::ostream_iterator<double>(oss, ", "));
46 oss << factors.back();