void test_serialization(const MultiIndexContainer& m)
{
  using namespace boost::multi_index;

  typedef typename MultiIndexContainer::iterator       iterator;
  typedef typename MultiIndexContainer::const_iterator const_iterator;

  std::ostringstream oss;
  {
    boost::archive::text_oarchive oa(oss);
    oa<<m;

    std::vector<const_iterator> its(m.size());
    const_iterator              it_end=m.end();
    for(const_iterator it=m.begin();it!=it_end;++it){
      its.push_back(it);
      oa<<const_cast<const const_iterator&>(its.back());
    }
    oa<<const_cast<const const_iterator&>(it_end);
  }

  MultiIndexContainer m2;
  std::istringstream iss(oss.str());
  boost::archive::text_iarchive ia(iss);
  ia>>m2;
  BOOST_CHECK(all_indices_equal(m,m2));

  iterator it_end=m2.end();
  for(iterator it=m2.begin();it!=it_end;++it){
    iterator it2;
    ia>>it2;
    BOOST_CHECK(it==it2);

    /* exercise safe mode with this (unchecked) iterator */
    BOOST_CHECK(*it==*it2);
    m2.erase(it,it2);
    m2.erase(it2,it2);
    m2.erase(it2,it);
    iterator it3(++it2);
    iterator it4;
    it4=--it2;
    BOOST_CHECK(it==it4);
    BOOST_CHECK(it==project<0>(m2,it4));
  }
  iterator it2;
  ia>>it2;
  BOOST_CHECK(it_end==it2);
  BOOST_CHECK(it_end==project<0>(m2,it2));
}
Ejemplo n.º 2
0
void intersect_by( const MultiIndexContainer& L1,const MultiIndexContainer& L2,MultiIndexContainer &s/*result*/, std::string msg="",
			 Tag* =0 /* fixes a MSVC++ 6.0 bug with implicit template function parms */
				  )
	{
	/* obtain a reference to the index tagged by Tag */

	const typename boost::multi_index::index<MultiIndexContainer,Tag>::type& L1_ID_index=
		get<Tag>(L1);
	const typename boost::multi_index::index<MultiIndexContainer,Tag>::type& L2_ID_index=
		get<Tag>(L2);
	typename boost::multi_index::index<MultiIndexContainer,Tag>::type::iterator  L1_ID_index_it;
	typename boost::multi_index::index<MultiIndexContainer,Tag>::type::iterator  L2_ID_index_it;
	//particlesID_set s;
	s.clear();
	std::set_intersection(
		L1_ID_index.begin(), 
		L1_ID_index.end(), 
		L2_ID_index.begin(), 
		L2_ID_index.end(),
		std::inserter(s, s.begin()), strComparator<Tag>()
		);
	//filter_by_ID();
	
	}
Ejemplo n.º 3
0
void test_stable_update()
{
  typedef typename MultiIndexContainer::iterator  iterator;
  typedef typename MultiIndexContainer::size_type size_type;

  MultiIndexContainer c;
  c.insert(0);
  c.insert(1);c.insert(1);
  c.insert(2);c.insert(2);c.insert(2);c.insert(2);
  c.insert(3);
  c.insert(4);c.insert(4);c.insert(4);
  c.insert(5);c.insert(5);
  c.insert(6);
  c.insert(7);
  size_type num_elems=
    c.count(0)+c.count(1)+c.count(2)+c.count(3)+
    c.count(4)+c.count(5)+c.count(6)+c.count(7);

  for(size_type n=c.size();n--;){
    iterator it=boost::next(c.begin(),n);

    c.replace(it,*it);
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    c.modify(it,do_nothing());
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    c.modify(it,do_nothing(),do_nothing());
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    for(int i=0;i<=8;++i){
      MultiIndexContainer cpy(c);
      bool b=c.modify(it,assign_value(i),assign_value(*it));
      BOOST_TEST(b||(size_type)std::distance(c.begin(),it)==n);
      BOOST_TEST(c.count(0)+c.count(1)+c.count(2)+c.count(3)+c.count(4)+
                  c.count(5)+c.count(6)+c.count(7)+c.count(8)==num_elems);
      if(b){
        c=cpy;
        it=boost::next(c.begin(),n);
      }
    }
  }
}