multi_index and VC70 problem

When compiling the following code on VC70 struct tTest { tTest() : x(0), y(0), z(0) int x,y,z; }; typedef multi_index_container< tTest, indexed_by< ordered_unique< composite_key< BOOST_MULTI_INDEX_MEMBER(tTest, int, x) ,BOOST_MULTI_INDEX_MEMBER(tTest, int, y) ) // replaced > with ) since gmane thinks I'm top-posting ) ) ) tTestList; void func() { tTestList u; u.insert(tTest()); } I get an error boost\multi_index\composite_key.hpp(573) : error C2100: illegal indirection boost\multi_index\ordered_index.hpp(562) : see reference to function template instantiation 'boost::multi_index::composite_key<Value,KeyFromValue0,KeyFromVal ue1,KeyFromValue2,KeyFromValue3,KeyFromValue4,KeyFromValue5,KeyFromValue6,KeyFr omValue7,KeyFromValue8,KeyFromValue9>::result_type boost::multi_index::composite_key<Value,KeyFromValue0,KeyFromValue1,KeyFromValu e2,KeyFromValue3,KeyFromValue4,KeyFromValue5,KeyFromValue6,KeyFromValue7,KeyFro mValue8,KeyFromValue9>::operator ()(const ChainedPtr &) const' being compiled with [ Value=boost::multi_index::member_offset<tTest,int,0>, KeyFromValue0=boost::multi_index::member_offset<tTest,int,4>, KeyFromValue1=boost::tuples::null_type, KeyFromValue2=boost::tuples::null_type, KeyFromValue3=boost::tuples::null_type, KeyFromValue4=boost::tuples::null_type, KeyFromValue5=boost::tuples::null_type, KeyFromValue6=boost::tuples::null_type, KeyFromValue7=boost::tuples::null_type, KeyFromValue8=boost::tuples::null_type, KeyFromValue9=boost::tuples::null_type, ChainedPtr=tTest ]

Martin <adrianm <at> touchdown.se> writes:
When compiling the following code on VC70
struct tTest { tTest() : x(0), y(0), z(0) int x,y,z; };
typedef multi_index_container< tTest, indexed_by< ordered_unique< composite_key< BOOST_MULTI_INDEX_MEMBER(tTest, int, x) ,BOOST_MULTI_INDEX_MEMBER(tTest, int, y) ) // replaced > with ) since gmane thinks I'm top-posting ) ) ) tTestList;
[...] Hi Martin, I haven't compiled your code, but I'm pretty confident the problem lies in the following: instead of composite_key< BOOST_MULTI_INDEX_MEMBER(tTest, int, x) ,BOOST_MULTI_INDEX_MEMBER(tTest, int, y) ) you should write composite_key< tTest ,BOOST_MULTI_INDEX_MEMBER(tTest, int, x) ,BOOST_MULTI_INDEX_MEMBER(tTest, int, y) ) i.e. the first parameter of composite_key is the value to which the extractors are applied. Please let me know if that solves the issue. Admittedly, the need for specifying the value in composite_key seems a little redundant, and the error messages don't help much, but there's no alternative AFAICS. Other than that, I'm always eager to get feedback from users of the lib, so if you have additional comments or suggestions please let me know. Best, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi Martin,
I haven't compiled your code, but I'm pretty confident the problem lies in the following: instead of
composite_key< BOOST_MULTI_INDEX_MEMBER(tTest, int, x) ,BOOST_MULTI_INDEX_MEMBER(tTest, int, y) )
you should write
composite_key< tTest ,BOOST_MULTI_INDEX_MEMBER(tTest, int, x) ,BOOST_MULTI_INDEX_MEMBER(tTest, int, y) )
i.e. the first parameter of composite_key is the value to which the extractors are applied. Please let me know if that solves the issue.
That was a quick reply and you are correct. It is the first time I use composite keys and I followed the examples. My error was that I thought the first class argument in the examples meant the identity comparison. Looking at it now I understand how stupid that was.
Other than that, I'm always eager to get feedback from users of the lib, so if you have additional comments or suggestions please let me know.
I work a lot with databases and I often have the need to store table like information in RAM. I often have a structure like struct table_t { string key; std::vector<subtable_t> subtable; }; The multi_index works perfectly for this. The only thing I am missing is a way to update the non-key elements in-place. Often my structures include subtables which means the copy can be expensive and I don't want to add member functions to update each member. Currently I do const_cast<std::vector<subtable>&>(itr->subtable).push_back(xxx); It would be nice if there was a macro or template that could do it in a safe way, i.e. ensure index isn't changed. nonkey(itr->subtable).push_back(xxx);

Martin <adrianm <at> touchdown.se> writes:
The only thing I am missing is a way to update the non-key elements in-place. Often my structures include subtables which means the copy can be expensive and I don't want to add member functions to update each member.
Currently I do
const_cast<std::vector<subtable>&>(itr->subtable).push_back(xxx);
It would be nice if there was a macro or template that could do it in a safe way, i.e. ensure index isn't changed.
nonkey(itr->subtable).push_back(xxx);
Well, you can build it yourself: template<typename T> T& deconst(const T& x) { return const_cast<T&>(x); } deconst(itr->subtable).push_back(xxx); But using this, you cannot really make the program enforce the immutability of keys, so you're basically on your being careful. No safe alternative that I know of by way of const_casting. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
Joaquin M Lopez Munoz
-
Martin