[multi_index_container] push_back?
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.
On Tue, Sep 9, 2008 at 2:19 PM, Robert Jones <robertgbjones@gmail.com> wrote:
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?
There is no push_back() method. You need to use insert. The ordered indices have a very similar interface to std::set. Regards, Pete
It depends on what your container consists of. Ordered Index allows only insert. If it would support sequenced or random access policies you would have the push_back member. Regards, Ovanes On Tue, Sep 9, 2008 at 3:19 PM, Robert Jones <robertgbjones@gmail.com>wrote:
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-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Tue, Sep 9, 2008 at 2:43 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:
It depends on what your container consists of. Ordered Index allows only insert. If it would support sequenced or random access policies you would have the push_back member.
Ahh! Got it, great - just added a first index of sequenced and off we go! Thanks Ovanes. - Rob.
On Tue, Sep 9, 2008 at 3:58 PM, Robert Jones <robertgbjones@gmail.com>wrote:
On Tue, Sep 9, 2008 at 2:43 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:
It depends on what your container consists of. Ordered Index allows only insert. If it would support sequenced or random access policies you would have the push_back member.
Ahh! Got it, great - just added a first index of sequenced and off we go!
But as suggested by Peter in another thread you can use std::inserter instead of back_inserter in your copy algorithm call, if you don't need to remember the insertion order at all. Good Luck, Ovanes
________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Robert Jones [robertgbjones@gmail.com] Enviado el: martes, 09 de septiembre de 2008 15:58 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] [multi_index_container] push_back?
On Tue, Sep 9, 2008 at 2:43 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:
It depends on what your container consists of. Ordered Index allows only insert. If it would support sequenced or random access policies you would have the push_back member.
Ahh! Got it, great - just added a first index of sequenced and off we go!
Remember that adding indices doesn't come for free in terms of space and time efficiency: http://www.boost.org/libs/multi_index/doc/performance.html So you should consider whether adding a sequenced index just to have push_back is worth the while. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (4)
-
JOAQUIN M. LOPEZ MUÑOZ
-
Ovanes Markarian
-
Peter Barker
-
Robert Jones