Boost logo

Boost :

Subject: [boost] [multi_index_container] push_back?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-09-09 09:19:27


Still having a little teething trouble with multi_index_container. This code,

#include <string>
#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;
using namespace boost :: multi_index;

struct Employee
{
  int id;
  std :: string name;
};

bool operator < ( Employee const & l, Employee const & r ) { return
l.id < r.id; }

int main( )
{
  typedef multi_index_container<
    Employee,
    indexed_by<
      ordered_unique<identity<Employee> >,
      ordered_non_unique<member<Employee, std :: string, & Employee :: name> >
>
> EmployeeSet;

  Employee employees[ ] = {
    { 1, "Adam" },
    { 2, "Craig" },
    { 3, "Brian" },
    { 4, "Dave" },
  };

  // EmployeeSet eSet( employees, employees + sizeof( employees ) /
sizeof( Employee ) );
  EmployeeSet eSet;
  std :: copy( employees, employees + sizeof( employees ) / sizeof(
Employee ), std :: back_inserter( eSet ) );

  return 0;
}

Gives me an error stating there is no push_back method on the container.

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_iterator.h:364:
error: 'class boost::multi_index::multi_index_con
tainer<Employee,
boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::identity<Employee
>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::member<Employee, std::string, &Employ
ee::name>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na
, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, std::allocator<Employee> >'
 has no member named 'push_back'

is there something I'm missing out?

Thanks, Rob.


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