要解决这个问题,您可以使用Lambda函数来替代std::function,并指定所需的参数类型。下面是一个示例代码:
#include
#include
#include
int main() {
std::unordered_map myMap = {{1, 10}, {2, 20}, {3, 30}};
// Lambda function with specified parameter types
auto myFunc = [](std::unordered_map::value_type pair) {
std::cout << "Key: " << pair.first << ", Value: " << pair.second << std::endl;
};
// Iterate through the map and call the lambda function
for (const auto& pair : myMap) {
myFunc(pair);
}
return 0;
}
在上面的示例中,我们使用Lambda函数来替代std::function,并指定了参数类型为std::unordered_map