2 #include <tr1/functional>
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
34 using std::tr1::placeholders::_1;
35 using std::tr1::placeholders::_2;
36 return std::accumulate(++factors.begin(), factors.end(), factors.front(),
37 bind(std::plus<double>(),
38 bind(std::multiplies<double>(), amount, _1),
42 std::string cost_func::to_string()
44 std::ostringstream oss;
45 std::copy(factors.begin(), --factors.end(),
46 std::ostream_iterator<double>(oss, ", "));
47 oss << factors.back();