我有一个这样的方法
template<typename T, typename U>
map<T,U> mapMapValues(map<T,U> old, T (f)(T,U))
{
map<T,U> new;
for(auto it = old.begin(); it != old.end(); ++it)
{
new[it->first] = f(it->first,it->second);
}
return new;
}
这个想法是你会像这样调用它
BOOST_AUTO_TEST_CASE(MapMapValues_basic)
{
map<int,int> test;
test[1] = 1;
map<int,int> transformedMap = VlcFunctional::mapMapValues(test,
[&](int key, int value) -> int
{
return key + 1;
}
);
}
然而我收到了错误信息:没有匹配参数列表的函数模板实例 "VlcFunctional::mapMapValues",参数类型为:(std::map, std::allocator>>, __lambda1)。
你有什么想法我做错了什么吗?我使用的是Visual Studio 2008和Intel C++编译器11.1。