[Multi-Index] Chained Ptr misunderstanding

Hi. I'm trying to use a shared_ptr as the value_type of a multi_index_container, but I'm not having any success with the key extractors (VS2005, 1.38).
From the doc, it seems that shared_ptr would be considered a Chained Pointer, and as such should work as-is, which by that I mean that I think I should be able to use the built-in key extractors whether value_type is a value or a shared_ptr. But I'm not having any luck. I found [1] which is very similar and which Joaquín answered, but I have other key extractors I want to use in different indexes, so I don't think using identity<> is applicable to my case in general, although it would be in this one. I'm trying to avoid having to write dumb custom key extractors for Foo, which would basically replicate what the built-in ones do in the first place.
It's most likely an error an my part, but I can't spot it. Can someone please help? Thanks, --DD [1] http://www.nabble.com/-multiindex--custom-key-extractor-problem-td20839161.h... #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> using namespace boost; using namespace boost::multi_index; typedef unsigned Uid; static Uid make_uid() { static Uid counter__ = 101; return ++counter__; } class Foo { public: Foo() : uid_(make_uid()) {} const Uid& uid() const { return uid_; } private: Uid uid_; }; typedef multi_index_container< shared_ptr<Foo>, indexed_by< ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN( shared_ptr<Foo>, const Uid&, uid ) > >
FooIndex;
int main() { FooIndex index; shared_ptr<Foo> p_foo(new Foo); BOOST_ASSERT(index.insert(p_foo).second); return 0; }

Dominique Devienne escribió:
Hi. I'm trying to use a shared_ptr as the value_type of a multi_index_container, but I'm not having any success with the key extractors (VS2005, 1.38).
[...] ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN( shared_ptr<Foo>, const Uid&, uid ) >
Replace the declaration above with ordered_unique< BOOST_MULTI_INDEX_CONST_MEM_FUN( Foo, const Uid&, uid )
That is, you must specifiy keys as if there weren't any intervening pointers --dereferencing is taken care of automatically by Boost.MultiIndex predefined extractors. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

On Tue, Apr 14, 2009 at 12:52 AM, <joaquin@tid.es> wrote:
Dominique Devienne escribió: That is, you must specifiy keys as if there weren't any intervening pointers --dereferencing is taken care of automatically by Boost.MultiIndex predefined extractors.
Thank you. --DD
participants (2)
-
Dominique Devienne
-
joaquin@tid.es