gpt4 book ai didi

c++ - 如何更新 boost::multi_index_container 中的重叠索引?

转载 作者:行者123 更新时间:2023-11-30 04:05:58 24 4
gpt4 key购买 nike

我使用的是 boost 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 进行修改将确保索引得到适当更新。但是“城市”索引的状态是什么?它是否已更新以反射(reflect)城市名称的变化?或者它处于损坏状态?我还能找到与旧城相同的地址索引吗?我必须单独更新这个索引吗?我可以调用空操作修改器来更新索引吗?

// 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 &) {});

最佳答案

在我看来应该没有问题:

文档提到:

Effects: Calls mod(e) where e is the element pointed to by position and rearranges *position into all the indices of the multi_index_container. Rearrangement is successful if

  • the index is non-unique OR no other element exists with equivalent key,
  • AND rearrangement is allowed by all other indices of the multi_index_container. If the rearrangement fails, the element is erased.

这意味着所有索引都已更新。请注意,所有索引原则上都可以拒绝编辑。您可能希望使用回滚来防止数据丢失。

关于c++ - 如何更新 boost::multi_index_container 中的重叠索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23070473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com