【发布时间】:2016-05-06 15:44:37
【问题描述】:
我有一个 boost::multi_index 容器。谁能告诉我如何根据某个键检索一系列迭代器?经过数小时的搜索,我得到了 lower_bound 或 upper_bound 应该可以解决问题的想法,但我仍然没有得到示例。在以下示例中,我想获取价格在 22 到 24 之间的所有迭代器。非常感谢。
struct order
{
unsigned int id;
unsigned int quantity;
double price;
order(unsigned int id_, unsigned int quantity_, double price_)
:id(id_), quantity(quantity_), price(price_){}
}
typedef multi_index_container<
order,
indexed_by<
ordered_unique<
tag<id>, BOOST_MULTI_INDEX_MEMBER(order, unsigned int, id),
std::greater<unsigned int>>,
ordered_non_unique<
tag<price>,BOOST_MULTI_INDEX_MEMBER(order ,double, price)>
>
> order_multi;
int main()
{
order_multi order_book;
order_book.insert(order(/*id=*/0, /*quantity=*/10, /*price=*/20));
order_book.insert(order(/*id=*/1, /*quantity=*/11, /*price=*/21));
order_book.insert(order(/*id=*/3, /*quantity=*/12, /*price=*/22));
order_book.insert(order(/*id=*/2, /*quantity=*/1, /*price=*/22));
order_book.insert(order(/*id=*/4, /*quantity=*/1, /*price=*/23));
order_book.insert(order(/*id=*/5, /*quantity=*/1, /*price=*/24));
order_book.insert(order(/*id=*/6, /*quantity=*/1, /*price=*/24));
order_book.insert(order(/*id=*/7, /*quantity=*/1, /*price=*/26));
}
【问题讨论】:
标签: c++ boost boost-multi-index