【发布时间】:2010-12-21 14:06:35
【问题描述】:
如何根据先前搜索的结果限制 boost::multi_index 中的搜索?
例如:假设我有一个矩形类,其内部值如下:
class MyRect
{
public:
int width;
int height;
double value;
}
并且我需要此类对象的数据结构来回答诸如“给定input_rectangle - 哪个对象MyRect 包含在该矩形中并且具有最高值?”之类的查询
我可以像这样使用“multi_index”:
struct given_value{};
struct given_width{};
struct given_height{};
typedef multi_index_container<MyRect,
indexed_by<
ordered_non_unique< tag<given_value>,
member<MyRect, double, &MyRect::value>,
ordered_non_unique< tag<given_width>,
member<MyRect, int, &MyRect::width>,
ordered_non_unique< tag<given_height>,
member<MyRect, int, &MyRect::height>, >
>
> MyDataStructure;
typedef MyDataStructure::index<given_width>::type MyDataStructureGivenWidth;
typedef MyDataStructureGivenWidth::iterator WidthIterator;
如果我的 input_rectangle 有宽度 input_width 我可以使用这样的东西:
WidthIterator start_iter = data_object.get<given_width>().begin();
WidthIterator end_iter = data_object.get<given_width>().upper_bound(input_width);
但是如何限制两个给定迭代器对 coresp 高度的搜索? (然后在该结果中找到具有最高值的对象?)
【问题讨论】:
标签: c++ search boost multi-index