题
我想在Boost Multi-Index内部实现两组具有相同搜索条件但不同驱逐标准的密钥。假设我有两组具有相同搜索条件的数据,但是一组需要MRU(最近使用)100的列表,另一组需要200个MRU。
class Student
{
int student_no;
char sex;
std::string address;
};
搜索标准是student_no,但是对于性别='m',我们需要200个MRU,对于性别='f',我们需要100个MRU。现在,我有一个解决方案,在其中介绍了一个新的有序索引来维护订购。
例如,indexSpecifierList将是这样的
typedef multi_index_container<
Student,
indexed_by<
ordered_unique< member<Student, int, &Student::student_no> >,
ordered_unique< composite_key<
member<Student, char, &Student::sex>,
member<Student, int, &Student::sex_specific_student_counter> > >
>
> student_set
现在,每次我都在插入一个新的,我必须使用索引2进行均等_range,并删除最旧的索引,如果重新使用了一些东西,我必须通过增加计数器来更新它。
有更好的解决方案解决这种问题吗?
谢谢,戈库尔。
解决方案
可以使用测序代替第二个索引并保持迭代剂将男性和女性作为缓存的迭代器进行操作。这有助于相同的行为。
不隶属于 StackOverflow