[multi_index] modify problem with composite_key

I am having problems using the modify method with my composite_key. Here is my multi_index container definition: typedef multi_index_container< entry, indexed_by< ordered_unique<member<entry,DataVertex,&entry::m_vertex> >, ordered_non_unique< composite_key< entry, member<entry,int,&entry::m_y>, member<entry,int,&entry::m_x> > > > > C; C m_c; namespace ll=boost::lambda; typedef nth_index<C,1>::type XYINDEX; I have a XYINDEX::iterator that is defined using the equal_range method of an XYINDEX order. Now I wish to modify the m_x attribute that this iterator points to so I attempt to write: inline void Positioner::updateX(XYIterator iter,int x) { m_c.modify(iter,(&ll::_1)->*&Positioner::entry::m_x=x); } I get this compiler error: positioner.h:77: error: no matching function for call to 'boost::multi_index::multi_index_container<Positioner::entry, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_vertex>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<Positioner::entry>
::modify(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Positioner::entry> , mpl_::na>&, const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2, boost::lambda::other_action<boost::lambda::member_pointer_action> >, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::addressof_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> , boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, int Positioner::entry::* const, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >)'
I have also tried: m_c.modify_key(iter,ll::_1=x); But this gives me this error: positioner.h:78: error: no matching function for call to 'boost::multi_index::multi_index_container<Positioner::entry, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_vertex>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<Positioner::entry>
::modify_key(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Positioner::entry> , mpl_::na>&, const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> , const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >)'
While a method like this compiles and works, I would like to be more efficent: inline void Positioner::updateX(DataVertex vertex,int x) { C::iterator iter=m_c.find(vertex); assert(iter!=m_c.end()); m_c.modify(iter,(&ll::_1)->*&Positioner::entry::m_x=x); } Can somebody tell me if what I'm trying to do is possible? If so, how?

Hi Jeffrey ----- Mensaje original ----- De: Jeffrey Holle <jeffreyholle@bellsouth.net> Fecha: Lunes, Septiembre 24, 2007 11:08 pm Asunto: [Boost-users] [multi_index] modify problem with composite_key Para: Boost Users mailing list <boost-users@lists.boost.org>
I am having problems using the modify method with my composite_key. Here is my multi_index container definition: typedef multi_index_container< entry, indexed_by< ordered_unique<member<entry,DataVertex,&entry::m_vertex> >, ordered_non_unique< composite_key< entry, member<entry,int,&entry::m_y>, member<entry,int,&entry::m_x> > > > > C;
C m_c; namespace ll=boost::lambda;
typedef nth_index<C,1>::type XYINDEX;
I have a XYINDEX::iterator that is defined using the equal_range method of an XYINDEX order. Now I wish to modify the m_x attribute that this iterator points to so I attempt to write:
inline void Positioner::updateX(XYIterator iter,int x) { m_c.modify(iter,(&ll::_1)->*&Positioner::entry::m_x=x); }
I get this compiler error: [...]
m_c.modify(...) implicitly uses the interface of C's index #0, yet you're passing it a XYIterator, which belongs to index #1. Iterators have to be matched with the index they're associated with: inline void Positioner::updateX(XYIterator iter,int x) { // note the get<1>() bit m_c.get<1>().modify( iter,(&ll::_1)->*&Positioner::entry::m_x=x); } Does it work now? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo PS: I posted an answer to some previous question of yours that you haven't confirmed yet: http://lists.boost.org/boost-users/2007/09/30804.php Is it all solved?

inline void Positioner::updateX(XYIterator iter,int x) { // note the get<1>() bit m_c.get<1>().modify( iter,(&ll::_1)->*&Positioner::entry::m_x=x); } Yes, this work fine, thanks!
PS: I posted an answer to some previous question of yours that you haven't confirmed yet: http://lists.boost.org/boost-users/2007/09/30804.php Is it all solved?
I've got two multi_index containers working fine now. I had a bit of trouble with the first one, which was involved in a fairly complex algorithm that was trouble-some to debug. My impressions from that experience is that: A. The iterator returned from erase was pointed somewhere that was obviously not right. I was erasing the 3rd element of a container holding 5 elements and the std::distance reported the correct results, but everything in the referenced element was zero. B. The iterators of the multi_index container become invalid after any modifications to the container. This was my biggest source of trouble... In general, I really like your container. The fact that it allows the swapping of key values was particularly useful.
participants (2)
-
"JOAQUIN LOPEZ MU?Z"
-
Jeffrey Holle