作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我尝试编译这样的代码:
bool server_utils::find_service_by_name_iterator_function(std::pair<boost::shared_ptr<service>, server_utils::service_description> const & element, std::string name) const
{
return element.second.name == name;
}
server_utils::service_description server_utils::stop_service_by_name(std::string name)
{
typedef std::map<boost::shared_ptr<service>, server_utils::service_description> map_t;
map_t::iterator map_it = std::find_if(description.service_map.begin(), description.service_map.end(), std::bind1st(std::ptr_fun(&server_utils::find_service_by_name_iterator_function), name));
if (map_it != description.service_map.end())
{
description.service_map.erase (map_it);
}
else
{
throw std::runtime_error("Service with such name was not found map not found!");
}
}
在哪里
struct service_description
{
//A service must have
std::string name;
std::string library_name;
std::string class_name;
std::string root_file_system_directory;
boost::property_tree::ptree service_custome_properties_tree;
//A service might have
std::vector<std::string> set_of_url_rules;
boost::unordered_multimap<std::string, std::string> set_of_header_rules;
boost::unordered_multimap<std::string, std::string> set_of_arguments_rules;
std::set<std::string> url_extensions;
std::string root_service_web_path;
};
但是我得到了奇怪的错误:
error C2784: 'std::pointer_to_binary_function<_Arg1,_Arg2,_Result,_Result(__cdecl *)(_Arg1,_Arg2)> std::ptr_fun(_Result (__cdecl *)(_Arg1,_Arg2))' : could not deduce template argument for '_Result (__cdecl *)(_Arg1,_Arg2)' from 'bool (__thiscall server_utils::* )(const std::pair<_Ty1,_Ty2> &,std::string) const'
error C2784: 'std::pointer_to_binary_function<_Arg1,_Arg2,_Result,_Result(__fastcall *)(_Arg1,_Arg2)> std::ptr_fun(_Result (__fastcall *)(_Arg1,_Arg2))' : could not deduce template argument for '_Result (__fastcall *)(_Arg1,_Arg2)' from 'bool (__thiscall server_utils::* )(const std::pair<_Ty1,_Ty2> &,std::string) const'
error C2784: 'std::pointer_to_unary_function<_Arg,_Result,_Result(__cdecl *)(_Arg)> std::ptr_fun(_Result (__cdecl *)(_Arg))' : could not deduce template argument for '_Result (__cdecl *)(_Arg)' from 'bool (__thiscall server_utils::* )(const std::pair<_Ty1,_Ty2> &,std::string) const'
error C2784: 'std::pointer_to_unary_function<_Arg,_Result,_Result(__stdcall *)(_Arg)> std::ptr_fun(_Result (__stdcall *)(_Arg))' : could not deduce template argument for '_Result (__stdcall *)(_Arg)' from 'bool (__thiscall server_utils::* )(const std::pair<_Ty1,_Ty2> &,std::string) const'
and so on...
我该怎么办?如何修复我的代码? boost.function 或 boost.bind 可以帮助我吗?
最佳答案
使用boost::bind
;它更聪明:
map_t::iterator map_it = std::find_if(
description.service_map.begin(), description.service_map.end(),
boost::bind(&server_utils::find_service_by_name_iterator_function, this, name));
关于c++ - 如何遍历这样的 map ?如何修复 8 个可怕的 C2784 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6701917/
我们在 session 中存储两个对象。不知何故,来自另一个用户的对象之一被加载到另一个用户的 session 中。用户应该无权访问此特定数据,一旦他们看到它,他们就知道出了什么问题。 我们有向他提供
我现在正在使用 Firefox 5 检查我的网站,我发现字体的呈现很糟糕。 这就是 Firefox (5) 和 Chrome 之间的区别:例如,看看文本 Jeffe 是如何呈现的... 默认字体系列是
我是一名优秀的程序员,十分优秀!