c++ - boost::multi_index 中的 Sql IN 模拟

标签 c++ boost boost-multi-index multi-index

我使用 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/

相关文章:

C++11:模板参数重新定义默认参数

c++ - 文本文件的C++ getline

c++ - 如何在 boost odeint bulirsch_stoer_dense_out 中插入解决方案

c++ - boost.multiindex 和值的地址作为键

c++ - boost multi_index_container 不编译

c++ - atof 只返回整数?

c++关闭后无法打开子窗口

c++ - 如何获取两个 boost ptime 之间的每个单独日期

c++ - 具有 boost::multiprecision::mpfr_float 的 Eigen3 动态矩阵