C++ 带用户定义比较器的boost bimap集合
我计划将自己的比较功能与boost bimap结合使用。我试图解决的问题是,当我使用带有指针的boostbimap时,比较不应该比较两个指针,而应该比较指针所指向的类 我尝试了以下代码。但它甚至没有编译。我做错了什么?还有没有一种更简单的方法来实现比较两个对象而不是两个指针的更少功能C++ 带用户定义比较器的boost bimap集合,c++,boost,bimap,C++,Boost,Bimap,我计划将自己的比较功能与boost bimap结合使用。我试图解决的问题是,当我使用带有指针的boostbimap时,比较不应该比较两个指针,而应该比较指针所指向的类 我尝试了以下代码。但它甚至没有编译。我做错了什么?还有没有一种更简单的方法来实现比较两个对象而不是两个指针的更少功能 typedef std::set规则集; 模板 布尔复合指针(常数myclass&lhs、常数myclass&rhs) { 返回((*lhs)
typedef std::set规则集;
模板
布尔复合指针(常数myclass&lhs、常数myclass&rhs)
{
返回((*lhs)<(*rhs));
}
typedef boost::bimap megarulebimap;
错误消息:
party1.cpp:104:64:错误:“template struct boost::bimaps::set_of”的模板参数列表中参数2的类型/值不匹配
party1.cpp:104:64:错误:应为类型,获取“comp_指针”
party1.cpp:104:70:错误:模板参数1无效
party1.cpp:104:85:错误:在“;”之前的声明中的类型无效令牌typedef std::set规则集;
typedef std::set<int> ruleset;
struct ruleset_cmp {
bool operator()(const ruleset *lhs, const ruleset *rhs) const
{
return ((*lhs) < (*rhs));
}
};
typedef boost::bimap<set_of<ruleset *, ruleset_cmp>, int> megarulebimap;
结构规则集{
布尔运算符()(常量规则集*lhs,常量规则集*rhs)常量
{
返回((*lhs)<(*rhs));
}
};
typedef boost::bimap megarulebimap;
好的。上面的代码片段很有效。这里似乎需要使用一个函子。typedef std::set ruleset;
结构规则集{
布尔运算符()(常量规则集*lhs,常量规则集*rhs)常量
{
返回((*lhs)<(*rhs));
}
};
typedef boost::bimap megarulebimap;
好的。上面的代码片段很有效。这里似乎需要使用函子。typedef std::set ruleset;结构规则集{cmp{bool操作符()(常量规则集*lhs,常量规则集*rhs)常量{return((*lhs)<(*rhs));};typedef boost::bimap megarulebimap;——此代码段工作类型定义std::set规则集;结构规则集{cmp{bool操作符()(常量规则集*lhs,常量规则集*rhs)常量{return((*lhs)<(*rhs));};typedef boost::bimap megarulebimap;——这段代码有效
typedef std::set<int> ruleset;
struct ruleset_cmp {
bool operator()(const ruleset *lhs, const ruleset *rhs) const
{
return ((*lhs) < (*rhs));
}
};
typedef boost::bimap<set_of<ruleset *, ruleset_cmp>, int> megarulebimap;