Why do I get the following compiler error
error: no matching function for call to 'memo(drawConnections_nicer2(const RangeVector&, std::function)::__lambda13)' });
with this code?
template<typename R, typename ... Args>
shared_ptr<function<R(Args...)> > memo(function<R(Args...)> fn)
{
map<tuple<Args...>,R> table;
return make_shared<function<R(Args...)> >([fn,table](Args... args) mutable ->
R {
auto argt = make_tuple(args...);
auto memoized = table.find(argt);
if(memoized==table.end())
{
auto result = fn(args...);
table[argt]=result;
return result;
}
else
{
return memoized->second;
}
});
}
...
shared_ptr<function<int(Range,int)> > calculate_level = memo([&](Range current, int pos) ->
int {
auto max_level = 0;
for(auto i=pos;i>=0;i--)
{
auto other = drawn[i];
if ( !(other.second<current.first || other.first>current.second) ) // intersects
{
max_level = max(max_level, (*calculate_level)(other,i-1)+1);
}
}
return max_level;
});
I thought that the lambda should be wrapped in a function object automatically here? Why is this not the case? Can I make do without the function parameter in memo?