1

ブースト 1.48.0 を使用していますが、アップグレードするオプションがありません。

重複する基準を持つインデックスを持つ multi_index_container を作成しました。次の例のように、同じ索引付け基準を共有する索引はどのように影響を受けますか? サンプル コードの最後の行は、私が何を求めているかを暗示しています。

struct street_address_key : composite_key<
    t_postal_address
    , const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::street_name>>
    , const_mem_fun<const_mem_fun<t_postal_address, long, &t_postal_address::house_number>>
    , const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::city>>
    , const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::state>>
    , const_mem_fun<const_mem_fun<t_postal_address, long, &t_postal_address::zip_code>>
> {};

multi_index<
    t_postal_address
    indexed_by<
        ordered_unique<street_address_key>
        , ordered_non_unique<const_mem_fun<t_postal_address, string, &t_postal_address::name>>
        , ordered_non_unique<const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::street_name>>
        , ordered_non_unique<const_mem_fun<const_mem_fun<t_postal_address, long, &t_postal_address::house_number>>
        , ordered_non_unique<const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::city>>
        , ordered_non_unique<const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::state>>
        , ordered_non_unique<const_mem_fun<const_mem_fun<t_postal_address, long, &t_postal_address::zip_code>>
    >
> t_address_book;

...

t_address_book::nth_element<0>::type::iterator address_iter = book.find(some_address_tuple);

book.modify(address_iter, modify_city_method);

auto city_range = book.get<4>().equal_range( \*???*\ );

都市インデックスは、street_address_key と同じ基準を共有します。私が理解しているように、street_address_key を介して変更すると、インデックスが適切に更新されます。しかし、「都市」インデックスの状態はどうですか? 都市名の変更を反映して更新されましたか? それとも壊れた状態ですか?旧市街と同じ住所インデックスを見つけることはできますか? このインデックスを個別に更新する必要がありますか? no-op Modifier を呼び出してインデックスを更新できますか?

// Presume I have the city element from the index.
// Is this supposed to update the city index after it was modified above?

book.get<4>().modify(city_iter, [](t_postal_address &) {});
4

2 に答える 2

1

問題はないように思えます:

ドキュメントには次のことが記載されています。

効果: mod(e) を呼び出します。ここで、e は position が指す要素*positionであり、multi_index_container のすべてのインデックスに再配置します。次の場合、再配置は成功です。

  • インデックスが一意ではないか、同等のキーを持つ要素が他に存在しません。
  • AND 再配置は、multi_index_container の他のすべてのインデックスで許可されます。再配置に失敗した場合、要素は消去されます。

これは、すべてのインデックスが更新されることを意味します。原則として、すべてのインデックスが編集を拒否できることに注意してください。ロールバックを使用して、データの損失を防ぐことができます。

于 2014-04-14T23:00:49.567 に答える