I am trying to pass a bound member function into a routine and have the result type be determined by the template class:
template< class Fun, class P>
auto splat(double start, double finish, int steps, Fun fun, double bias)
{
typedef BOOST_TYPEOF(Fun) Fun_type;
typedef boost::function_traits<Fun_type> function_traits;
typedef boost::function_traits<Fun_type>::result_type P;
vector<P> out = vector<P>(steps);
double a = steps;
a = a / 2;
double step = (finish - start) / (steps - 1);
double param = start;
for (int i = 0; i < steps; i++)
{
out[i] = fun(param);
param += step*(1 + accel*(i - a - 1) / (a - 1));
}
return out;
}
The calling sequence is:
std::function<BallLib::Point(double)> pFun = std::bind(&BallPath::path, one, _1);
Point ppp = pFun(0.0);
vector<Point> line = testspread::splat(0.0, 3.1415, 10, pFun, 0.0);
It fails to compile with Severity Code Description Project File Line Error C2783 'std::vector> testspread::splat(double,double,int,Fun,double)': could not deduce template argument for 'P'
How do I get it to determine P?
as the output, but then I got 15 random errors.
– doby Apr 09 '16 at 15:17