2

I use boost::multi_index and retrieve data like this:

sample_set::index<my_indx>::type::iterator s, end;
boost::tie(s,end) = samples.get<my_indx>().equal_range(
    boost::make_tuple( "Dress", "Red" ));

This code retrieves all red dresses. Is there any way to retrieve red and yellow dresses with one query? Like in SQL:

"Select * from clothes where type = 'Dress' and color in ('Red', 'Yellow')"
Alexander Ponomarev
  • 2,598
  • 3
  • 24
  • 31
  • 1
    It looks like you can write your own compares with a composite_key_compare http://www.boost.org/doc/libs/1_53_0/libs/multi_index/doc/reference/key_extraction.html#composite_key_compare –  Jun 17 '13 at 14:20

1 Answers1

3

There's no way of doing that with one single operation: Boost.MultiIndex lookup member functions always return ranges (or iterators, that can be thought of as one-element ranges), but the result of such a query as you describe is not a range --its elements are not necessarily adjacent. So you've got to do two queries, one for ("Dress","Red") and one for ("Dress","Yellow"), and then traverse the two resulting ranges in sequence.

Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20
  • Could one filter the container (indexed range) with Boost Ranges filtered? http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/adaptors/reference/filtered.html – alfC Jan 22 '18 at 06:36