Boost logo

Boost Users :

Subject: Re: [Boost-users] Container with insertion order
From: Igor R (boost.lists_at_[hidden])
Date: 2011-11-23 11:26:52


> It is very difficult to realize?

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/random_access_index.hpp>

using namespace boost::multi_index;

struct item
{
        item(int i) : i_(i)
        {}
  int i_;
};

typedef multi_index_container<
  item,
        indexed_by<
                random_access<>,
                ordered_non_unique<member<item, int, &item::i_> >
>
> container;

int main()
{
        container c;
        c.insert(c.end(), item(2));
        c.insert(c.end(), item(1));
        c.insert(c.end(), item(3));
        c.insert(c.end(), item(4));
        for (container::const_iterator i = c.begin(); i != c.end(); ++i)
                std::cout << i->i_ << std::endl;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net