multi_index with shared_ptr

Hello, I having difficulties getting multi_index working with shared_ptr Example code: typedef multi_index_container< NodePtr, indexed_by< ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodePtr, handle, getHandle) > > > node_set; NodePtr is a typedef to boost::shared_ptr<NodeBase> NodeBase is an interface for other NodeTypes objects the use it. NodeBase ::getHandle() : handle (handle==size_t) Using MSVC++ 6.0 compilers complains that getHandle is not a member of NodePtr If I replace NodePtr with NodeBase class it compiles, with a price of giving away shared_ptr abilty. Does anyone have any idea how to get both libs work? Regards Tal Agmon

tal boost ha escrito:
Hello,
I having difficulties getting multi_index working with shared_ptr
Example code:
typedef multi_index_container<
NodePtr,
indexed_by<
ordered_unique<
BOOST_MULTI_INDEX_CONST_MEM_FUN(NodePtr, handle, getHandle)
>
>
> node_set;
NodePtr is a typedef to boost::shared_ptr<NodeBase>
NodeBase is an interface for other NodeTypes objects the use it.
NodeBase ::getHandle() : handle (handle==size_t)
Using MSVC++ 6.0 compilers complains that getHandle is not a member of NodePtr
If I replace NodePtr with NodeBase class it compiles, with a price of giving away shared_ptr abilty.
Does anyone have any idea how to get both libs work?
OK. You should define your NodePtr_set as follows typedef multi_index_container< NodePtr, indexed_by< ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle) > >
NodePtr_set;
Note that elements are NodePtrs, but the index is based on NodeBase. This is explained at http://boost.org/libs/multi_index/doc/advanced_topics.html#advanced_key_extr... It is possible that you missed that part.
Regards Tal Agmon
Best regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi, Trying someting like this typedef NodePtrSet::index<hndl>::type index_hndl_type; //complier complains two few arguments Note: hndl is a tag name //// so I defined the following: typedef nth_index<NodePtrSet,0>::type hndl_index_type; typedef nth_index<NodePtrSet,1>::type group_index_type; ... When I try to write group_index_type& g_type = get<group>(ns); // tag<group> complier tells me the I have to increase /Zm which i did.(to /Zm1024) but still I receive this annoying message. z:\boost\mpl\aux_\preprocessed\msvc60\iter_fold_if_impl.hpp(65) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit If I apply this line instead hndl_index_type & h_type = get<hndl>(ns); I get the following errors: //error C2667: 'get' : none of 2 overload have a best conversion //error C2668: 'get' : ambiguous call to overloaded function What I care is to get access using my keys and I don't know how to do it I am able to run on the first one with no problem e.g doing the following NodePtrSet::iterator it = ns.find(theHandle); //works 1. How to i rewrite the latter line to explictly tell it to find theHandle? 2. How to I get access to the non_unique_index This is too good to give up on Can someone help me? Regards, t.a On 2/20/06, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
tal boost ha escrito:
Hello,
I having difficulties getting multi_index working with shared_ptr
Example code:
typedef multi_index_container<
NodePtr,
indexed_by<
ordered_unique<
BOOST_MULTI_INDEX_CONST_MEM_FUN(NodePtr, handle, getHandle)
>
>
> node_set;
NodePtr is a typedef to boost::shared_ptr<NodeBase>
NodeBase is an interface for other NodeTypes objects the use it.
NodeBase ::getHandle() : handle (handle==size_t)
Using MSVC++ 6.0 compilers complains that getHandle is not a member of NodePtr
If I replace NodePtr with NodeBase class it compiles, with a price of giving away shared_ptr abilty.
Does anyone have any idea how to get both libs work?
OK. You should define your NodePtr_set as follows
typedef multi_index_container< NodePtr, indexed_by< ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle) > >
NodePtr_set;
Note that elements are NodePtrs, but the index is based on NodeBase.
This is explained at
http://boost.org/libs/multi_index/doc/advanced_topics.html#advanced_key_extr...
It is possible that you missed that part.
Regards Tal Agmon
Best regards,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hello Tal, tal boost <tal.boost <at> gmail.com> writes:
Hi,
Trying someting like this typedef NodePtrSet::index<hndl>::type index_hndl_type; //complier complains two few arguments Note: hndl is a tag name
I assume from previous posts of yours that you're using MSVC++ 6.0, right? If so, you cannot use the syntax your_container_type::index<...>, as explained in: http://boost.org/libs/multi_index/doc/compiler_specifics.html#msvc_60 Please have a good read at this, since MSVC++ 6.0 has serious limitations affecting the usage of Boost.MultiIndex. Making the lib work for this compiler is not for the faint of heart, although it can be done.
//// so I defined the following:
typedef nth_index<NodePtrSet,0>::type hndl_index_type; typedef nth_index<NodePtrSet,1>::type group_index_type;
OK. Note that what makes this compile, as compared with your previous attempt, is not the use of nth_index (though this might help), but your choice of global nth_index instead of // won't work in MSVC++ 6.0 typedef NodePtrSet::nth_index<0>::type hndl_index_type; typedef NodePtrSet::nth_index<1>::type group_index_type; as explained in the aforementioned page.
... When I try to write group_index_type& g_type = get<group>(ns); // tag<group> complier tells me the I have to increase /Zm which i did.(to /Zm1024) but still I receive this annoying message.
z:\boost\mpl\aux_\preprocessed\msvc60\iter_fold_if_impl.hpp(65) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
If I apply this line instead
hndl_index_type & h_type = get<hndl>(ns);
I get the following errors: //error C2667: 'get' : none of 2 overload have a best conversion //error C2668: 'get' : ambiguous call to overloaded function
What I care is to get access using my keys and I don't know how to do it
Your first problem has been reported in the past and is somewhat alleviated in the version of Boost.MultiIndex shipping with Boost 1.34; as for the second problem I don't really know what's happening, some sample code showing that behavior would be useful. Anyway, my suggestion is that you entirely omit the use of tags (i.e, define the indices without tags) and use ordinals instead: hndl_index_type & h_type = get<0>(ns); group_index_type& g_type = get<1>(ns); As it happens, omitting tags seem to greatly relieve stress on the compiler. Furthermore, by using enums you can have some of the convenience of tags: enum{hndl=0,group=1}; ... hndl_index_type & h_type = get<hndl>(ns); group_index_type& g_type = get<group>(ns); Please try this approach and report your results back. Thank you!
I am able to run on the first one with no problem e.g doing the following NodePtrSet::iterator it = ns.find(theHandle); //works 1. How to i rewrite the latter line to explictly tell it to find theHandle?
I don't get you. This is exactly what the line above does.
2. How to I get access to the non_unique_index
Hopefully my prior suggestion on using ordinals rather than tags will help here.
This is too good to give up on
I'm glad you like the lib, despite the effort it takes to make it work under MSVC++ 6.0. Modern compilers don't choke that much, in case you can consider upgrading. Good luck with your project. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi, Thanks for all your suggestions I will do more reading regarding compiler specifics Hopefuly I will upgrade my compiler this year. Ok, I had tried this approach: hndl_index_type & h_type = get<0>(ns); group_index_type& g_type = get<1>(ns); But got: error C2667: 'get' : none of 2 overload have a best conversion error C2668: 'get' : ambiguous call to overloaded function Anymore suggestions? (Pls) I do have to admit that I find It strange that all the examples on the web (1-9) compile successfully. which left me wonder what am I missing In my project. Regards, Tal Agmon On 2/21/06, Joaquin M Lopez Munoz <joaquin@tid.es> wrote:
Hello Tal,
tal boost <tal.boost <at> gmail.com> writes:
Hi,
Trying someting like this typedef NodePtrSet::index<hndl>::type index_hndl_type; //complier complains two few arguments Note: hndl is a tag name
I assume from previous posts of yours that you're using MSVC++ 6.0, right? If so, you cannot use the syntax your_container_type::index<...>, as explained in:
http://boost.org/libs/multi_index/doc/compiler_specifics.html#msvc_60
Please have a good read at this, since MSVC++ 6.0 has serious limitations affecting the usage of Boost.MultiIndex. Making the lib work for this compiler is not for the faint of heart, although it can be done.
//// so I defined the following:
typedef nth_index<NodePtrSet,0>::type hndl_index_type; typedef nth_index<NodePtrSet,1>::type group_index_type;
OK. Note that what makes this compile, as compared with your previous attempt, is not the use of nth_index (though this might help), but your choice of global nth_index instead of
// won't work in MSVC++ 6.0 typedef NodePtrSet::nth_index<0>::type hndl_index_type; typedef NodePtrSet::nth_index<1>::type group_index_type;
as explained in the aforementioned page.
... When I try to write group_index_type& g_type = get<group>(ns); // tag<group> complier tells me the I have to increase /Zm which i did.(to /Zm1024) but still I receive this annoying message.
z:\boost\mpl\aux_\preprocessed\msvc60\iter_fold_if_impl.hpp(65) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
If I apply this line instead
hndl_index_type & h_type = get<hndl>(ns);
I get the following errors: //error C2667: 'get' : none of 2 overload have a best conversion //error C2668: 'get' : ambiguous call to overloaded function
What I care is to get access using my keys and I don't know how to do it
Your first problem has been reported in the past and is somewhat alleviated in the version of Boost.MultiIndex shipping with Boost 1.34; as for the second problem I don't really know what's happening, some sample code showing that behavior would be useful.
Anyway, my suggestion is that you entirely omit the use of tags (i.e, define the indices without tags) and use ordinals instead:
hndl_index_type & h_type = get<0>(ns); group_index_type& g_type = get<1>(ns);
As it happens, omitting tags seem to greatly relieve stress on the compiler. Furthermore, by using enums you can have some of the convenience of tags:
enum{hndl=0,group=1};
...
hndl_index_type & h_type = get<hndl>(ns); group_index_type& g_type = get<group>(ns);
Please try this approach and report your results back. Thank you!
I am able to run on the first one with no problem e.g doing the following NodePtrSet::iterator it = ns.find(theHandle); //works 1. How to i rewrite the latter line to explictly tell it to find theHandle?
I don't get you. This is exactly what the line above does.
2. How to I get access to the non_unique_index
Hopefully my prior suggestion on using ordinals rather than tags will help here.
This is too good to give up on
I'm glad you like the lib, despite the effort it takes to make it work under MSVC++ 6.0. Modern compilers don't choke that much, in case you can consider upgrading.
Good luck with your project.
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

tal boost ha escrito:
Hi,
Thanks for all your suggestions I will do more reading regarding compiler specifics Hopefuly I will upgrade my compiler this year.
Ok, I had tried this approach:
hndl_index_type & h_type = get<0>(ns); group_index_type& g_type = get<1>(ns);
But got: error C2667: 'get' : none of 2 overload have a best conversion error C2668: 'get' : ambiguous call to overloaded function
Anymore suggestions? (Pls)
Could you provide some sample code (either through the list or privately)? If this is not an option, please paste the complete error message, so that I can see what are the clashing overloads the compiler is referring to. I've never met a similar problem. If nothing else works, you can always explicitly qualify get: hndl_index_type & h_type = boost::multi_index::get<0>(ns);
I do have to admit that I find It strange that all the examples on the web (1-9) compile successfully. which left me wonder what am I missing In my project.
My suspicion is that you've got some extra using directive that is causing the ambiguity problems. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Applying full qualify hndl_index_type & h_type = boost::multi_index::get<0>(ns); I get this error ////////////////////////////////// Compiling... CADDB.CPP z:\ctcadlib\include\db\caddb.cpp(258) : error C2440: 'initializing' : cannot convert from 'const class boost::multi_index::detail::ordered_index<struct boost::multi_index::const_mem_fun_explicit<class CtCAD::NodeBase,unsigned int,unsigned int (__thi scall CtCAD::NodeBase::*)(void)const ,&[thunk]: __thiscall `vcall'{56,{flat}}' >,struct std::less<unsigned int>,struct boost::multi_index::detail::nth_layer<1,class boost::shared_ptr<class CtCAD::NodeBase>,struct boost::multi_index::indexed_by<struc t boost::multi_index::ordered_unique<struct boost::multi_index::const_mem_fun_explicit<class CtCAD::NodeBase,unsigned int,unsigned int (__thiscall CtCAD::NodeBase::*)(void)const ,&[thunk]: __thiscall `vcall'{56,{flat}}' >,struct boost::mpl::na,struc t boost::mpl::na>,struct boost::multi_index::ordered_non_unique<struct boost::multi_index::const_mem_fun_explicit<class CtCAD::NodeBase,int,int (__thiscall CtCAD::NodeBase::*)(void)const ,&[thunk]: __thiscall `vcall'{44,{flat}}' >,struct boost::mpl: :na,struct boost::mpl::na>,struct boost::mpl::na,struct boost::mpl::na,struct boost::mpl::na>,class std::allocator<class boost::shared_ptr<class CtCAD::NodeBase> > >,struct boost::mpl::vector0<struct boost::mpl::na>,struct boost::multi_index::detail ::ordered_unique_tag>' to 'class boost::multi_index::detail::ordered_index<struct boost::multi_index::const_mem_fun_explicit<class CtCAD::NodeBase,unsigned int,unsigned int (__thiscall CtCAD::NodeBase::*)(void)const ,&[thunk]: __thiscall `vcall'{56, {flat}}' >,struct std::less<unsigned int>,struct boost::multi_index::detail::nth_layer<1,class boost::shared_ptr<class CtCAD::NodeBase>,struct boost::multi_index::indexed_by<struct boost::multi_index::ordered_unique<struct boost::multi_index::const_ mem_fun_explicit<class CtCAD::NodeBase,unsigned int,unsigned int (__thiscall CtCAD::NodeBase::*)(void)const ,&[thunk]: __thiscall `vcall'{56,{flat}}' >,struct boost::mpl::na,struct boost::mpl::na>,struct boost::multi_index::ordered_non_unique<struct boost::multi_index::const_mem_fun_explicit<class CtCAD: :NodeBase,int,int (__thiscall CtCAD::NodeBase::*)(void)const ,&[thunk]: __thiscall `vcall'{44,{flat}}' >,struct boost::mpl::na,struct boost::mpl::na>,struct boost::mpl::na,struct boost::mpl::na,struct boost::mpl::na>,class std::allocator<class boost ::shared_ptr<class CtCAD::NodeBase> > >,struct boost::mpl::vector0<struct boost::mpl::na>,struct boost::multi_index::detail::ordered_unique_tag> &' Conversion loses qualifiers Error executing cl.exe. //////////////////////////
My suspicion is that you've got some extra using directive that is causing the ambiguity problems.
I will send you on a private channel some source files so maybe you can find out what is the problem. Regards, Tal On 2/22/06, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
tal boost ha escrito:
Hi,
Thanks for all your suggestions I will do more reading regarding compiler specifics Hopefuly I will upgrade my compiler this year.
Ok, I had tried this approach:
hndl_index_type & h_type = get<0>(ns); group_index_type& g_type = get<1>(ns);
But got: error C2667: 'get' : none of 2 overload have a best conversion error C2668: 'get' : ambiguous call to overloaded function
Anymore suggestions? (Pls)
Could you provide some sample code (either through the list or privately)? If this is not an option, please paste the complete error message, so that I can see what are the clashing overloads the compiler is referring to.
I've never met a similar problem. If nothing else works, you can always explicitly qualify get:
hndl_index_type & h_type = boost::multi_index::get<0>(ns);
I do have to admit that I find It strange that all the examples on the web (1-9) compile successfully. which left me wonder what am I missing In my project.
My suspicion is that you've got some extra using directive that is causing the ambiguity problems.
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

tal boost ha escrito:
Applying full qualify hndl_index_type & h_type = boost::multi_index::get<0>(ns); I get this error ////////////////////////////////// Compiling... CADDB.CPP z:\ctcadlib\include\db\caddb.cpp(258) : error C2440: 'initializing' : cannot convert from 'const class
[...]
I will send you on a private channel some source files so maybe you can find out what is the problem.
I think the problem is precisely what Martin Bonner point out in his response: you're doing hndl_index_type & h_type = boost::multi_index::get<0>(ns); inside a *const* method of your class (this I checked inspecting the code you sent me privately), so that the member variable ns is treated as const as well, and get<...>() on a const container return const index references. So, please write const hndl_index_type & h_type = boost::multi_index::get<0>(ns); and try again. If this works, you might want to omit explicit qualification and see what happens. As for your question on how to replicate the sentence NodePtrSet::iterator it = ns.find(theHandle); to work for the second index, it is like this: group_index_type::iterator it = get<1>(ns).find(theGroup); or const group_index_type& g_type = get<1>(ns); group_index_type::iterator it = g_type.find(theGroup); Please note that index #0 iterators are of a different type than index #1 iterators. You cannot mix them, but they're sort of translatable by means of project: http://boost.org/libs/multi_index/doc/tutorial.html#projection
Regards, Tal
Best, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (3)
-
Joaquin M Lopez Munoz
-
Joaquín Mª López Muñoz
-
tal boost