我使用 boost::multi_index 并检索如下数据:
sample_set::index<my_indx>::type::iterator s, end;
boost::tie(s,end) = samples.get<my_indx>().equal_range(
boost::make_tuple( "Dress", "Red" ));
此代码检索所有红色连衣裙。有没有办法通过一次查询检索红色和黄色的衣服?就像 SQL 中一样:
"Select * from clothes where type = 'Dress' and color in ('Red', 'Yellow')"
最佳答案
没有办法通过单个操作来做到这一点:Boost.MultiIndex 查找成员函数总是返回范围(或迭代器,可以被认为是单元素范围),但是您所描述的这样的查询不是一个范围——它的元素不一定是相邻的。因此,您必须执行两次查询,一次查询 ("Dress","Red"),一次查询 ("Dress","Yellow"),然后按顺序遍历两个结果范围。
关于c++ - boost::multi_index 中的 Sql IN 模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17149448/