Boost logo

Boost :

Subject: Re: [boost] [multi_index_container] Compiling the examples
From: David Walthall (walthall_at_[hidden])
Date: 2008-09-09 11:29:19


Robert Jones wrote:
> Trying to multi_index_container I'm getting these compile errors. Apart from
> #include <string> and using namespace boost this lifted verbatim from
> the example documentation.
>
> #include <string>
>
> struct employee
> {
> int id;
> std::string name;
>
> employee(int id,const std::string& name):id(id),name(name){}
>
> bool operator<(const employee& e)const{return id<e.id;}
> };
>
> #include <boost/multi_index_container.hpp>
> #include <boost/multi_index/ordered_index.hpp>
> #include <boost/multi_index/identity.hpp>
> #include <boost/multi_index/member.hpp>
>
> using namespace boost;
>
> // define a multiply indexed set with indices by id and name
> typedef multi_index_container<
> employee,
> indexed_by<
> // sort by employee::operator<
> ordered_unique<identity<employee> >,
>
> // sort by less<string> on name
> ordered_non_unique<member<employee,std::string,&employee::name> >
> >
>> employee_set;
>
> My error is
>
> multi.cpp:23: error: `indexed_by' was not declared in this scope
> multi.cpp:25: error: `ordered_unique' was not declared in this scope
> multi.cpp:25: error: `identity' was not declared in this scope
> multi.cpp:25: error: template argument 2 is invalid
> multi.cpp:25: error: expected unqualified-id before '>' token
> multi.cpp:25: error: expected `,' or `;' before '>' token
>
> I'm using Boost 1.36 and gcc 3.4.4 (maybe this too old?). Can anyone
> tell me what I'm doing wrong?

Hi Rob,

The compiler is complaining because it can't find some of the types that
live in boost::multi_index. You can either add
   using namespace boost::multi_index;
or qualify the types:
// define a multiply indexed set with indices by id and name
typedef boost::multi_index_container<
   employee,
   boost::multi_index::indexed_by<
     // sort by employee::operator<
 
boost::multi_index::ordered_unique<boost::multi_index::identity<employee> >,

     // sort by less<string> on name
 
boost::multi_index::ordered_non_unique<boost::multi_index::member<employee,std::string,&employee::name>
>
>
> employee_set;

David


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk