[multi_index] invalid expression as template parameter

Hello, I use multi_index as follow with success: typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, handle, getHandle) >, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, group_id, memberOf) > > > NodePtrSet; but I would like NodeBase inherite boost::enable_shared_from_this<NodeBase> I get error C2964: invalid expression as template parameter using msvc 6 any idea?

Tal Agmon ha escrito:
Hello,
I use multi_index as follow with success:
typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, handle, getHandle) >, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, group_id, memberOf) > > > NodePtrSet;
but I would like NodeBase inherite boost::enable_shared_from_this<NodeBase> I get error C2964: invalid expression as template parameter using msvc 6
any idea?
Hello Tal, Some more context is needed: the following complete snippet compiles and works fine in MSVC 6.5, so your problem must depend on some other circumstance that you haven't described sufficiently: ******** BEGIN CODE ******** #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> typedef int handle; typedef int group_id; struct NodeBase:boost::enable_shared_from_this<NodeBase> { NodeBase(handle h,group_id gid):h(h),gid(gid){} group_id memberOf()const{return gid;} handle getHandle()const{return h;} private: group_id gid; handle h; }; typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle) >, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,group_id,memberOf) >
NodePtrSet;
int main() { NodePtrSet ns; typedef boost::shared_ptr<NodeBase> element_type; ns.insert(element_type(new NodeBase(0,0))); ns.insert(element_type(new NodeBase(1,0))); ns.insert(element_type(new NodeBase(2,1))); return 0; } ******** END CODE ******** Could you maybe come up with a reproducible test case showing the problem? Best regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi Joaquin, NodeBase is an interface struct NodeBase{ virtual group_id memberOf()const=0; ...}; NodeBase<<interface >> used by NodeCommon and other Nodes uses NodeCommon in a relationship of is-a Best Regards, Tal Agmon On 5/22/06, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
Tal Agmon ha escrito:
Hello,
I use multi_index as follow with success:
typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, handle, getHandle) >, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, group_id, memberOf) > > > NodePtrSet;
but I would like NodeBase inherite boost::enable_shared_from_this<NodeBase> I get error C2964: invalid expression as template parameter using msvc 6
any idea?
Hello Tal,
Some more context is needed: the following complete snippet compiles and works fine in MSVC 6.5, so your problem must depend on some other circumstance that you haven't described sufficiently:
******** BEGIN CODE ******** #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp>
typedef int handle; typedef int group_id;
struct NodeBase:boost::enable_shared_from_this<NodeBase> { NodeBase(handle h,group_id gid):h(h),gid(gid){}
group_id memberOf()const{return gid;} handle getHandle()const{return h;}
private: group_id gid; handle h; };
typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle)
, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,group_id,memberOf)
NodePtrSet;
int main() { NodePtrSet ns;
typedef boost::shared_ptr<NodeBase> element_type;
ns.insert(element_type(new NodeBase(0,0))); ns.insert(element_type(new NodeBase(1,0))); ns.insert(element_type(new NodeBase(2,1)));
return 0; }
******** END CODE ********
Could you maybe come up with a reproducible test case showing the problem?
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

Please see below code #CODE BEGIN #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> typedef int handle; typedef int group_id; struct NodeBase :boost::enable_shared_from_this<NodeBase>{ virtual group_id memberOf()const=0; virtual handle getHandle()const=0; }; struct NodeType: NodeBase { NodeType(handle h,group_id gid):h(h),gid(gid){} group_id memberOf()const{return gid;} handle getHandle()const{return h;} private: group_id gid; handle h; }; typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle)
, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,group_id,memberOf)
NodePtrSet;
int main() { NodePtrSet ns; typedef boost::shared_ptr<NodeBase> element_type; ns.insert(element_type(new NodeType(0,0))); ns.insert(element_type(new NodeType(1,0))); ns.insert(element_type(new NodeType(2,1))); return 0; } #CODE END On 5/22/06, Tal Agmon <tal.boost@gmail.com> wrote:
Hi Joaquin,
NodeBase is an interface
struct NodeBase{ virtual group_id memberOf()const=0; ...};
NodeBase<<interface >> used by NodeCommon and other Nodes uses NodeCommon in a relationship of is-a
Best Regards, Tal Agmon
On 5/22/06, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
Tal Agmon ha escrito:
Hello,
I use multi_index as follow with success:
typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, handle, getHandle) >, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase, group_id, memberOf) > > > NodePtrSet;
but I would like NodeBase inherite boost::enable_shared_from_this<NodeBase> I get error C2964: invalid expression as template parameter using msvc 6
any idea?
Hello Tal,
Some more context is needed: the following complete snippet compiles and works fine in MSVC 6.5, so your problem must depend on some other circumstance that you haven't described sufficiently:
******** BEGIN CODE ******** #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp>
typedef int handle; typedef int group_id;
struct NodeBase:boost::enable_shared_from_this<NodeBase> { NodeBase(handle h,group_id gid):h(h),gid(gid){}
group_id memberOf()const{return gid;} handle getHandle()const{return h;}
private: group_id gid; handle h; };
typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle)
, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,group_id,memberOf)
NodePtrSet;
int main() { NodePtrSet ns;
typedef boost::shared_ptr<NodeBase> element_type;
ns.insert(element_type(new NodeBase(0,0))); ns.insert(element_type(new NodeBase(1,0))); ns.insert(element_type(new NodeBase(2,1)));
return 0; }
******** END CODE ********
Could you maybe come up with a reproducible test case showing the problem?
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

Tal Agmon ha escrito:
Please see below code
OK, now I can reproduce it. This is indeed MSVC 6.0 bug (one more): I've tried with GCC and ICC 7.1, and everything goes smooth. Fortunately, you can always resort to manually writing your key extractors, as described in http://tinyurl.com/l3g6u; the following workaround with user-defined key extractors has been checked to work with MSVC 6.5. Hope it helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo ******** BEGIN CODE ******** #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> typedef int handle; typedef int group_id; struct NodeBase:boost::enable_shared_from_this<NodeBase> { virtual ~NodeBase(){} virtual group_id memberOf()const=0; virtual handle getHandle()const=0; }; struct NodeType:NodeBase { NodeType(handle h,group_id gid):h(h),gid(gid){} virtual group_id memberOf()const{return gid;} virtual handle getHandle()const{return h;} private: group_id gid; handle h; }; struct NodeBaseHandleExtractor { typedef handle result_type; result_type operator()(const boost::shared_ptr<NodeBase>& x) { return x->getHandle(); } }; struct NodeBaseGroupIdExtractor { typedef group_id result_type; result_type operator()(const boost::shared_ptr<NodeBase>& x) { return x->memberOf(); } }; typedef boost::multi_index::multi_index_container< boost::shared_ptr<NodeBase>, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< NodeBaseHandleExtractor >, boost::multi_index::ordered_non_unique< NodeBaseGroupIdExtractor >
NodePtrSet;
int main() { NodePtrSet ns; typedef boost::shared_ptr<NodeBase> element_type; ns.insert(element_type(new NodeType(0,0))); ns.insert(element_type(new NodeType(1,0))); ns.insert(element_type(new NodeType(2,1))); return 0; } ******** END CODE ********
participants (2)
-
Joaquín Mª López Muñoz
-
Tal Agmon