I have a boost::multi_index container. Could anybody tell me how to retrieve a range of iterators based on a certain key? After hours of search I got the idea that lower_bound or upper_bound should do the trick but I still do not got an example. In following example I would like to get all the iterators with price between 22 and 24. Thank you very much.
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));
}