Hey Joaquin
First of all, thank you so much for your repeated help.
In line with the example provided, I've written a generic find_and_modify function as:
template <typename T, typename F> Segment* find_and_modify(T& iterable, F filters, State s, double a_arr=-1, Comment rmk=Comment::INFO_SEGMENT_PREDICTED) {
auto iter = iterable.find(filters);
if (iter == iterable.end())
return nullptr;
std::pair<typename T::iterator, typename T::iterator> iter_main = iterable.equal_range(filters);
while (iter_main.first != iter_main.second) {
auto it = boost::multi_index::project<aux>(segment, iter_main.first);
segment.get<aux>().modify(
it,
[&s, &a_arr, &rmk](Segment& seg) {
seg.state = s;
if (a_arr != -1)
seg.a_arr = a_arr;
if (rmk != +Comment::INFO_SEGMENT_PREDICTED) {
seg.comment = rmk;
}
}
);
iter_main.first++;
}
return (Segment *)(&(*iter));
}
where T is an index on container instance segment as segment.get<sometag>();
This seems to work well for the most part but it still segfaults. Any ideas what I'm doing wrong. As specified in the SO answer, I've created an aux index and projected the current iterator to it so as to not modify the current iterator, and yet on debugging the function, I've found that iter_main.first evaluates to garbage at some point as:
(gdb) p (*iter_main.first)
$7 = (const boost::multi_index::detail::index_node_base<Segment, std::allocator<Segment> >::value_type &) @0x6b3c10: {
index = " \252\355\000\000\000\000\000\020\376u\000\000\000\000\000\060\355u\000\000\000\000\000\020\376u\000\000\000\000\000\320\361j\000\000\000\000\000\360:r\000\000\000\000\000\270۾\366\377\177\000\000\270۾\366\377\177\000\000\310۾\366\377\177\000\000\310۾\366\377\177\000\000\330۾\366\377\177\000\000\330۾\366\377\177\000\000\260\363u\000\000\000\000\000\260\363u\000\000\000\000\000`;k\000\000\000\000\000`;k\000\000\000\000\000\200\227j\000\000\000\000\000\200\227j\000\000\000\000\000\030ܾ\366\377\177\000\000\030ܾ\366\377\177\000\000(ܾ\366\377\177\000\000(ܾ\366\377\177\000\000\070ܾ\366\377\177\000\000\070ܾ\366\377\177\000\000Hܾ\366\377\177\000\000"..., code = "OP", cname = "34283", p_arr = 1450614300, p_dep = 1450667229, a_arr = 3, a_dep = inf, t_inb_proc = 3600, t_agg_proc = 0, t_out_proc = 18000, cost = 0,
state = {static _size_constant = 5, _value = 3 '\003'}, comment = {static _size_constant = 9, _value = 2 '\002'}, parent = 0x75ed70}