problem with multi_index_container -> find

Hello, I don't understand why this code doesn't compile (gcc-3.3.1) '... id_index.find( id) ...' ? Regards, Oliver #include <iostream> #include <string> #include <utility> #include <boost/multi_index_container.hpp> #include <boost/multi_index/key_extractors.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/tuple/tuple.hpp> namespace mi = boost::multi_index; struct phonebook_entry { int id; std::string family_name; std::string given_name; phonebook_entry( int id_, std::string const& family_name_, std::string const& given_name_) : id( id_), family_name( family_name_), given_name( given_name_) {} }; typedef mi::multi_index_container< phonebook_entry, mi::indexed_by< mi::ordered_non_unique< mi::composite_key< phonebook_entry, mi::member< phonebook_entry, std::string, & phonebook_entry::family_name >, mi::member< phonebook_entry, std::string, & phonebook_entry::given_name > > >, mi::ordered_unique< mi::member< phonebook_entry, int, & phonebook_entry::id > > >
phonebook;
void test_multi_index() { phonebook pb; phonebook::nth_index< 0 >::type & name_index = pb.get< 0 >(); std::string family_name("Mann"); std::string given_name("Thomas"); std::pair< phonebook::iterator, phonebook::iterator > p = name_index.equal_range( boost::make_tuple( family_name, given_name) ); while ( p.first != p.second) { std::cout << p.first->family_name << ", " << p.first->given_name << std::endl; ++p.first; } phonebook::nth_index< 1 >::type & id_index = pb.get< 1 >(); int id = 1; phonebook::iterator itr = id_index.find( id); // <<== doesn't // error: conversion from ` boost::multi_index::detail::index_iterator<boost::multi_index::detail::o rdered_index_node<boost::multi_index::detail::index_node_base<phonebook_ entry> > >' to non-scalar type ` // boost::multi_index::detail::index_iterator<boost::multi_index::detail::o rdered_index_node<boost::multi_index::detail::ordered_index_node<boost:: multi_index::detail::index_node_base<phonebook_entry> > > >' //requested phonebook::iterator end = id_index.end(); if ( itr != end) std::cout << itr->family_name << ", " << itr->given_name << std::endl; }
participants (1)
-
Oliver.Kowalke@infineon.com