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 の高さの検索を、与えられた 2 つの反復子で制限するにはどうすればよいでしょうか? (その後、その結果で最も高い値を持つオブジェクトを見つけますか?)