added random access indices

[SVN r32669]
This commit is contained in:
Joaquín M. López Muñoz 2006-02-06 15:52:21 +00:00
parent e953c2b4ff
commit 7274eca56c
11 changed files with 430 additions and 108 deletions

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex basic test.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -41,14 +41,15 @@ void test_basic()
const employee_set_by_age& i2=get<2>(es);
employee_set_as_inserted& i3=get<3>(es);
employee_set_by_ssn& i4=get<ssn>(es);
employee_set_randomly& i5=get<randomly>(es);
es.insert(employee(0,"Joe",31,1123));
es.insert(employee(5,"Anna",41,1123)); /* clash*/
es.insert(employee(5,"Anna",41,1123)); /* clash*/
i1.insert(employee(1,"Robert",27,5601));
es.insert(employee(2,"John",40,7889));
i3.push_back(employee(3,"Albert",20,9012));
i4.insert(employee(4,"John",57,1002));
i4.insert(employee(0,"Andrew",60,2302)); /* clash */
i5.push_back(employee(0,"Andrew",60,2302)); /* clash */
v.push_back(employee(0,"Joe",31,1123));
v.push_back(employee(1,"Robert",27,5601));
@ -60,6 +61,7 @@ void test_basic()
/* by insertion order */
BOOST_CHECK(std::equal(i3.begin(),i3.end(),v.begin()));
BOOST_CHECK(std::equal(i5.begin(),i5.end(),v.begin()));
}
{

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for capacity memfuns.
*
* Copyright 2003-2005 Joaqu匤 M L<EFBFBD>ez Mu<EFBFBD>z.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -52,4 +52,29 @@ void test_capacity()
ss.resize(5);
BOOST_CHECK(ss.size()==5);
multi_index_container<int,indexed_by<random_access<> > > rs;
rs.resize(10);
BOOST_CHECK(rs.size()==10);
BOOST_CHECK(rs.size()<=rs.max_size());
BOOST_CHECK(rs.size()<=rs.capacity());
rs.resize(20);
BOOST_CHECK(rs.size()==20);
BOOST_CHECK(rs.size()<=rs.capacity());
unsigned int c=rs.capacity();
rs.resize(5);
BOOST_CHECK(rs.size()==5);
BOOST_CHECK(rs.capacity()==c);
rs.reserve(100);
BOOST_CHECK(rs.size()==5);
BOOST_CHECK(rs.capacity()>=100);
c=rs.capacity();
rs.reserve(99);
BOOST_CHECK(rs.size()==5);
BOOST_CHECK(rs.capacity()==c);
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for comparison functions.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -28,11 +28,23 @@ struct lookup_list{
> type;
};
template<typename Value>
struct lookup_vector{
typedef multi_index_container<
Value,
indexed_by<
random_access<>,
ordered_non_unique<identity<Value> >
>
> type;
};
void test_comparison()
{
employee_set es;
employee_set_by_age& i2=get<2>(es);
employee_set_as_inserted& i3=get<3>(es);
employee_set_randomly& i5=get<5>(es);
es.insert(employee(0,"Joe",31,1123));
es.insert(employee(1,"Robert",27,5601));
es.insert(employee(2,"John",40,7889));
@ -42,21 +54,26 @@ void test_comparison()
employee_set es2;
employee_set_by_age& i22=get<age>(es2);
employee_set_as_inserted& i32=get<3>(es2);
es.insert(employee(0,"Joe",31,1123));
es.insert(employee(1,"Robert",27,5601));
es.insert(employee(2,"John",40,7889));
es.insert(employee(3,"Albert",20,9012));
employee_set_randomly& i52=get<5>(es2);
es2.insert(employee(0,"Joe",31,1123));
es2.insert(employee(1,"Robert",27,5601));
es2.insert(employee(2,"John",40,7889));
es2.insert(employee(3,"Albert",20,9012));
BOOST_CHECK(es==es&&es<=es&&es>=es&&
i22==i22&&i22<=i22&&i22>=i22&&
i32==i32&&i32<=i32&&i32>=i32);
i32==i32&&i32<=i32&&i32>=i32&&
i52==i52&&i52<=i52&&i52>=i52);
BOOST_CHECK(es!=es2&&es2<es&&es>es2&&!(es<=es2)&&!(es2>=es));
BOOST_CHECK(i2!=i22&&i22<i2&&i2>i22&&!(i2<=i22)&&!(i22>=i2));
BOOST_CHECK(i3!=i32&&i32<i3&&i3>i32&&!(i3<=i32)&&!(i32>=i3));
BOOST_CHECK(i5!=i52&&i52<i5&&i5>i52&&!(i5<=i52)&&!(i52>=i5));
lookup_list<int>::type l1;
lookup_list<char>::type l2;
lookup_list<long>::type l3;
lookup_list<int>::type l1;
lookup_list<char>::type l2;
lookup_vector<char>::type l3;
lookup_list<long>::type l4;
lookup_vector<long>::type l5;
l1.push_back(3);
l1.push_back(4);
@ -70,15 +87,31 @@ void test_comparison()
l2.push_back(char(1));
l2.push_back(char(2));
l3.push_back(long(3));
l3.push_back(long(4));
l3.push_back(long(5));
l3.push_back(long(1));
l3.push_back(char(3));
l3.push_back(char(4));
l3.push_back(char(5));
l3.push_back(char(1));
l3.push_back(char(2));
l4.push_back(long(3));
l4.push_back(long(4));
l4.push_back(long(5));
l4.push_back(long(1));
l5.push_back(long(3));
l5.push_back(long(4));
l5.push_back(long(5));
l5.push_back(long(1));
BOOST_CHECK(l1==l2&&l1<=l2&&l1>=l2);
BOOST_CHECK(
get<1>(l1)==get<1>(l2)&&get<1>(l1)<=get<1>(l2)&&get<1>(l1)>=get<1>(l2));
BOOST_CHECK(l1!=l3&&l3<l1&&l1>l3);
BOOST_CHECK(
get<1>(l1)!=get<1>(l3)&&get<1>(l1)<get<1>(l3)&&get<1>(l3)>get<1>(l1));
get<1>(l1)==get<1>(l3)&&get<1>(l1)<=get<1>(l3)&&get<1>(l1)>=get<1>(l3));
BOOST_CHECK(l1!=l4&&l4<l1&&l1>l4);
BOOST_CHECK(
get<1>(l1)!=get<1>(l4)&&get<1>(l1)<get<1>(l4)&&get<1>(l4)>get<1>(l1));
BOOST_CHECK(l3!=l5&&l5<l3&&l3>l5);
BOOST_CHECK(
get<1>(l3)!=get<1>(l5)&&get<1>(l3)<get<1>(l5)&&get<1>(l5)>get<1>(l3));
}

View File

@ -1,7 +1,7 @@
/* Boost.MultiIndex test for interconvertibilty between const and
* non-const iterators.
*
* Copyright 2003-2005 Joaqu匤 M L<EFBFBD>ez Mu<EFBFBD>z.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -59,6 +59,16 @@ void test_conv_iterators()
employee_set_as_inserted::const_iterator it1=i3.begin();
employee_set_as_inserted::const_iterator it2=ci3.begin();
BOOST_CHECK(it==it1&&it1==it2&&it2==it);
BOOST_CHECK(*it==*it1&&*it1==*it2&&*it2==*it);
}
{
employee_set_randomly& i5=get<5>(es);
const employee_set_randomly& ci5=get<5>(es);
employee_set_randomly::iterator it=i5.begin();
employee_set_randomly::const_iterator it1=i5.begin();
employee_set_randomly::const_iterator it2=ci5.begin();
BOOST_CHECK(it==it1&&it1==it2&&it2==it);
BOOST_CHECK(*it==*it1&&*it1==*it2&&*it2==*it);
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for copying and assignment.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -21,6 +21,29 @@
using namespace boost::multi_index;
template<typename Sequence>
static void test_assign(BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence))
{
Sequence s;
int a[]={0,1,2,3,4,5};
std::size_t sa=sizeof(a)/sizeof(a[0]);
s.assign(&a[0],&a[sa]);
BOOST_CHECK(s.size()==sa&&std::equal(s.begin(),s.end(),&a[0]));
s.assign(&a[0],&a[sa]);
BOOST_CHECK(s.size()==sa&&std::equal(s.begin(),s.end(),&a[0]));
s.assign((std::size_t)18,37);
BOOST_CHECK(s.size()==18&&std::accumulate(s.begin(),s.end(),0)==666);
s.assign((std::size_t)12,167);
BOOST_CHECK(s.size()==12&&std::accumulate(s.begin(),s.end(),0)==2004);
}
void test_copy_assignment()
{
employee_set es;
@ -31,6 +54,7 @@ void test_copy_assignment()
al=get<2>(es).get_allocator();
al=get<3>(es).get_allocator();
al=get<4>(es).get_allocator();
al=get<5>(es).get_allocator();
BOOST_CHECK(es2.empty());
@ -47,6 +71,7 @@ void test_copy_assignment()
BOOST_CHECK(es2==es3);
BOOST_CHECK(get<2>(es2)==get<2>(es3));
BOOST_CHECK(get<3>(es2)==get<3>(es3));
BOOST_CHECK(get<5>(es2)==get<5>(es3));
employee_set es4;
employee_set_by_name& i1=get<name>(es4);
@ -66,39 +91,33 @@ void test_copy_assignment()
BOOST_CHECK(i3==get<3>(es2));
employee_set es7;
employee_set_randomly& i5=get<randomly>(es7);
i5=get<5>(es2);
BOOST_CHECK(i5==get<5>(es2));
std::list<employee> l;
l.push_back(employee(3,"Anna",31,5388));
l.push_back(employee(1,"Rachel",27,9012));
l.push_back(employee(2,"Agatha",40,1520));
#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
employee_set es7;
es7.insert(l.begin(),l.end());
employee_set es8;
es8.insert(l.begin(),l.end());
#else
employee_set es7(l.begin(),l.end());
employee_set es8(l.begin(),l.end());
#endif
l.sort();
BOOST_CHECK(es7.size()==l.size()&&
std::equal(es7.begin(),es7.end(),l.begin()));
BOOST_CHECK(es8.size()==l.size()&&
std::equal(es8.begin(),es8.end(),l.begin()));
multi_index_container<int,indexed_by<sequenced<> > > ss;
/* MSVC++ 6.0 chokes on test_assign without this explicit instantiation */
multi_index_container<int,indexed_by<sequenced<> > > s1;
test_assign<multi_index_container<int,indexed_by<sequenced<> > > >();
int a[]={0,1,2,3,4,5};
std::size_t sa=sizeof(a)/sizeof(a[0]);
ss.assign(&a[0],&a[sa]);
BOOST_CHECK(ss.size()==sa&&std::equal(ss.begin(),ss.end(),&a[0]));
ss.assign(&a[0],&a[sa]);
BOOST_CHECK(ss.size()==sa&&std::equal(ss.begin(),ss.end(),&a[0]));
ss.assign((std::size_t)18,37);
BOOST_CHECK(ss.size()==18&&std::accumulate(ss.begin(),ss.end(),0)==666);
ss.assign((std::size_t)12,167);
BOOST_CHECK(ss.size()==12&&std::accumulate(ss.begin(),ss.end(),0)==2004);
multi_index_container<int,indexed_by<random_access<> > > s2;
test_assign<multi_index_container<int,indexed_by<random_access<> > > >();
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for iterators.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -95,7 +95,7 @@ void test_non_const_hashed_iterators(Index& i,int target)
}
template<typename Index>
void test_const_hashed_iterators(Index& i,int target)
void test_const_hashed_iterators(const Index& i,int target)
{
typedef typename Index::const_iterator const_iterator;
typedef typename Index::const_local_iterator const_local_iterator;
@ -115,6 +115,90 @@ void test_const_hashed_iterators(Index& i,int target)
BOOST_CHECK(n==target&&n==m);
}
template<typename Index>
void test_non_const_rnd_iterators(Index& i,int target)
{
typedef typename Index::iterator iterator;
typedef typename Index::reverse_iterator reverse_iterator;
typedef typename Index::difference_type difference_type;
iterator middle=i.begin()+(i.end()-i.begin())/2;
difference_type off=middle-i.begin();
reverse_iterator rmiddle=i.rbegin()+off;
bool odd=((i.end()-i.begin())%2)!=0;
int n=0;
for(iterator it=i.begin();it!=middle;++it){
n+=it->id;
n+=it[off].id;
}
if(odd)n+=(--i.end())->id;
int m=0;
for(reverse_iterator rit=i.rbegin();rit!=rmiddle;++rit){
m+=rit->id;
m+=(rit+off)->id;
}
if(odd)m+=(--i.rend())->id;
int p=0;
for(iterator it2=i.end();it2!=middle;){
--it2;
p+=it2->id;
p+=(it2-off)->id;
}
if(odd)p-=middle->id;
int q=0;
for(reverse_iterator rit2=i.rend();rit2!=rmiddle;){
--rit2;
q+=rit2->id;
q+=(rit2-off)->id;
}
if(odd)q-=rmiddle->id;
BOOST_CHECK(n==target&&n==m&&n==p&&n==q);
}
template<typename Index>
void test_const_rnd_iterators(const Index& i,int target)
{
typedef typename Index::const_iterator const_iterator;
typedef typename Index::const_reverse_iterator const_reverse_iterator;
typedef typename Index::difference_type difference_type;
const_iterator middle=i.begin()+(i.end()-i.begin())/2;
difference_type off=middle-i.begin();
const_reverse_iterator rmiddle=i.rbegin()+off;
bool odd=((i.end()-i.begin())%2)!=0;
int n=0;
for(const_iterator it=i.begin();it!=middle;++it){
n+=it->id;
n+=it[off].id;
}
if(odd)n+=(--i.end())->id;
int m=0;
for(const_reverse_iterator rit=i.rbegin();rit!=rmiddle;++rit){
m+=rit->id;
m+=(rit+off)->id;
}
if(odd)m+=(--i.rend())->id;
int p=0;
for(const_iterator it2=i.end();it2!=middle;){
--it2;
p+=it2->id;
p+=(it2-off)->id;
}
if(odd)p-=middle->id;
int q=0;
for(const_reverse_iterator rit2=i.rend();rit2!=rmiddle;){
--rit2;
q+=rit2->id;
q+=(rit2-off)->id;
}
if(odd)q-=rmiddle->id;
BOOST_CHECK(n==target&&n==m&&n==p&&n==q);
}
void test_iterators()
{
employee_set es;
@ -137,4 +221,6 @@ void test_iterators()
test_const_iterators (get<3>(es),target);
test_non_const_hashed_iterators(get<4>(es),target);
test_const_hashed_iterators (get<4>(es),target);
test_non_const_rnd_iterators (get<5>(es),target);
test_const_rnd_iterators (get<5>(es),target);
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for standard list operations.
*
* Copyright 2003-2004 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -18,6 +18,7 @@
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/test/test_tools.hpp>
using namespace boost::multi_index;
@ -64,19 +65,13 @@ bool is_sorted(
}
}
void test_list_ops()
template<typename Sequence>
static void test_list_ops_unique_seq(BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence))
{
typedef multi_index_container<
int,
indexed_by<
ordered_unique<identity<int> >,
sequenced<>
>
> sequenced_set;
typedef nth_index<sequenced_set,1>::type sequenced_index;
typedef typename nth_index<Sequence,1>::type sequenced_index;
sequenced_set ss,ss2;
sequenced_index &si=get<1>(ss),&si2=get<1>(ss2);
Sequence ss,ss2;
sequenced_index &si=get<1>(ss),&si2=get<1>(ss2);
si.push_front(0); /* 0 */
si.push_front(4); /* 40 */
@ -130,8 +125,8 @@ void test_list_ops()
BOOST_CHECK(si2.empty());
{
sequenced_set ss3(ss);
sequenced_index &si3=get<1>(ss3);
Sequence ss3(ss);
sequenced_index &si3=get<1>(ss3);
si3.sort(std::greater<int>());
si.reverse();
@ -144,6 +139,74 @@ void test_list_ops()
si.merge(si2,std::greater<int>());
BOOST_CHECK(is_sorted(si,std::greater<int>()));
BOOST_CHECK(si2.empty());
}
template<typename Sequence>
static void test_list_ops_non_unique_seq(
BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence))
{
typedef typename Sequence::iterator iterator;
Sequence ss;
for(int i=0;i<10;++i){
ss.push_back(i);
ss.push_back(i);
ss.push_front(i);
ss.push_front(i);
} /* 9988776655443322110000112233445566778899 */
ss.unique();
CHECK_EQUAL(
ss,
{9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 _ 0 _
1 _ 2 _ 3 _ 4 _ 5 _ 6 _ 7 _ 8 _ 9});
iterator it=ss.begin();
for(int j=0;j<9;++j,++it){} /* it points to o */
Sequence ss2;
ss2.splice(ss2.end(),ss,ss.begin(),it);
ss2.reverse();
ss.merge(ss2);
CHECK_EQUAL(
ss,
{0 _ 1 _ 1 _ 2 _ 2 _ 3 _ 3 _ 4 _ 4 _ 5 _ 5 _
6 _ 6 _ 7 _ 7 _ 8 _ 8 _ 9 _ 9});
ss.unique(same_integral_div<3>());
CHECK_EQUAL(ss,{0 _ 3 _ 6 _ 9});
ss.unique(same_integral_div<1>());
CHECK_EQUAL(ss,{0 _ 3 _ 6 _ 9});
}
void test_list_ops()
{
typedef multi_index_container<
int,
indexed_by<
ordered_unique<identity<int> >,
sequenced<>
>
> sequenced_set;
/* MSVC++ 6.0 chokes on test_list_ops_unique_seq without this
* explicit instantiation
*/
sequenced_set ss;
test_list_ops_unique_seq<sequenced_set>();
typedef multi_index_container<
int,
indexed_by<
ordered_unique<identity<int> >,
random_access<>
>
> random_access_set;
random_access_set rs;
test_list_ops_unique_seq<random_access_set>();
typedef multi_index_container<
int,
@ -151,34 +214,13 @@ void test_list_ops()
> int_list;
int_list il;
for(int i=0;i<10;++i){
il.push_back(i);
il.push_back(i);
il.push_front(i);
il.push_front(i);
} /* 9988776655443322110000112233445566778899 */
test_list_ops_non_unique_seq<int_list>();
il.unique();
CHECK_EQUAL(
il,
{9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 _ 0 _
1 _ 2 _ 3 _ 4 _ 5 _ 6 _ 7 _ 8 _ 9});
typedef multi_index_container<
int,
indexed_by<random_access<> >
> int_vector;
int_list::iterator it=il.begin();
for(int j=0;j<9;++j,++it){} /* it points to o */
int_list il2;
il2.splice(il2.end(),il,il.begin(),it);
il2.reverse();
il.merge(il2);
CHECK_EQUAL(
il,
{0 _ 1 _ 1 _ 2 _ 2 _ 3 _ 3 _ 4 _ 4 _ 5 _ 5 _
6 _ 6 _ 7 _ 7 _ 8 _ 8 _ 9 _ 9});
il.unique(same_integral_div<3>());
CHECK_EQUAL(il,{0 _ 3 _ 6 _ 9});
il.unique(same_integral_div<1>());
CHECK_EQUAL(il,{0 _ 3 _ 6 _ 9});
int_vector iv;
test_list_ops_non_unique_seq<int_vector>();
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for modifier memfuns.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -25,6 +25,7 @@ void test_modifiers()
employee_set_by_age& i2=get<age>(es);
employee_set_as_inserted& i3=get<as_inserted>(es);
employee_set_by_ssn& i4=get<ssn>(es);
employee_set_randomly& i5=get<randomly>(es);
es.insert(employee(0,"Joe",31,1123));
BOOST_CHECK(es.insert(employee(0,"Joe",31,1123)).second==false);
@ -45,19 +46,28 @@ void test_modifiers()
employee_set_as_inserted::iterator it3=i3.begin();
i3.insert(it3,100,employee(3,"Judy",39,6201));
BOOST_CHECK((--it3)->ssn==6201);
BOOST_CHECK(es.size()==4);
employee_set_randomly::iterator it5=i5.begin();
i5.insert(it5,100,employee(4,"Jill",52,3379));
BOOST_CHECK(i5.begin()->age==52);
BOOST_CHECK(es.size()==5);
es.erase(employee(1,"Joe Jr.",5,2563));
BOOST_CHECK(i2.size()==3&&i3.size()==3);
BOOST_CHECK(i3.size()==4&&i5.size()==4);
BOOST_CHECK(i1.erase("Judy")==1);
BOOST_CHECK(es.size()==2&&i2.size()==2);
BOOST_CHECK(es.size()==3&&i2.size()==3);
BOOST_CHECK(i2.erase(it2)->age==64);
BOOST_CHECK(es.size()==1&&i1.size()==1);
BOOST_CHECK(i2.erase(it2)->age==52);
BOOST_CHECK(i3.size()==2&&i4.size()==2);
i3.pop_front();
BOOST_CHECK(es.size()==0&&i2.size()==0);
BOOST_CHECK(i1.size()==1&&i2.size()==1);
i5.erase(i5.begin(),i5.end());
BOOST_CHECK(es.size()==0&&i3.size()==0);
es.insert(employee(0,"Joe",31,1123));
BOOST_CHECK(i1.erase(i1.begin())==i1.end());
@ -80,6 +90,27 @@ void test_modifiers()
i3.pop_front();
BOOST_CHECK(es.size()==0);
i5.push_back(employee(1,"Jack",31,5032));
i5.push_front(employee(0,"Joe",31,1123));
i5.insert(i5.end()-1,employee(2,"Grandda Joe",64,7881));
BOOST_CHECK(i5.back()==employee(1,"Jack",31,5032));
BOOST_CHECK(i5.front()==employee(0,"Joe",31,1123));
BOOST_CHECK(i5[0]==i5.front()&&i5.at(0)==i5.front());
BOOST_CHECK(i5[i5.size()-1]==i5.back()&&i5.at(i5.size()-1)==i5.back());
i5.pop_front();
BOOST_CHECK(i5.back()==employee(1,"Jack",31,5032));
BOOST_CHECK(i5.front()==employee(2,"Grandda Joe",64,7881));
BOOST_CHECK(es.size()==2);
i5.pop_back();
BOOST_CHECK(i5.back()==employee(2,"Grandda Joe",64,7881));
BOOST_CHECK(i5.front()==i5.front());
BOOST_CHECK(es.size()==1);
i5.erase(i5.begin());
BOOST_CHECK(es.size()==0);
std::vector<employee> ve;
ve.push_back(employee(3,"Anna",31,5388));
ve.push_back(employee(1,"Rachel",27,9012));
@ -88,7 +119,7 @@ void test_modifiers()
i1.insert(ve.begin(),ve.end());
BOOST_CHECK(i2.size()==3);
BOOST_CHECK(i4.erase(i4.begin(),i4.end())==i4.end());
BOOST_CHECK(i2.erase(i2.begin(),i2.end())==i2.end());
BOOST_CHECK(es.size()==0);
i2.insert(ve.begin(),ve.end());
@ -101,6 +132,19 @@ void test_modifiers()
i3.insert(i3.end(),ve.begin(),ve.end());
BOOST_CHECK(es.size()==3);
BOOST_CHECK(i4.erase(9012)==1);
i4.erase(i4.begin());
BOOST_CHECK(i4.erase(i4.begin(),i4.end())==i4.end());
i4.insert(ve.begin(),ve.end());
BOOST_CHECK(i5.size()==3);
BOOST_CHECK(i5.erase(i5.begin(),i5.end())==i5.end());
BOOST_CHECK(es.size()==0);
i5.insert(i5.begin(),ve.begin(),ve.end());
BOOST_CHECK(i1.size()==3);
BOOST_CHECK(es.erase(es.begin(),es.end())==es.end());
BOOST_CHECK(i2.size()==0);
@ -128,6 +172,12 @@ void test_modifiers()
i3.swap(get<3>(es2));
BOOST_CHECK(es==es2_backup&&es2==es_backup);
i4.swap(get<4>(es2));
BOOST_CHECK(es==es_backup&&es2==es2_backup);
i5.swap(get<5>(es2));
BOOST_CHECK(es==es2_backup&&es2==es_backup);
#if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL)
::boost::multi_index::detail::swap(i1,get<1>(es2));
#else
@ -155,6 +205,24 @@ void test_modifiers()
BOOST_CHECK(es==es_backup&&es2==es2_backup);
#if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL)
::boost::multi_index::detail::swap(i4,get<4>(es2));
#else
using std::swap;
swap(i4,get<4>(es2));
#endif
BOOST_CHECK(es==es2_backup&&es2==es_backup);
#if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL)
::boost::multi_index::detail::swap(i5,get<5>(es2));
#else
using std::swap;
swap(i5,get<5>(es2));
#endif
BOOST_CHECK(es==es_backup&&es2==es2_backup);
i3.clear();
BOOST_CHECK(i3.size()==0);
@ -162,6 +230,10 @@ void test_modifiers()
i4.clear();
BOOST_CHECK(i4.size()==0);
es=es2;
i5.clear();
BOOST_CHECK(i5.size()==0);
es2.clear();
BOOST_CHECK(es2.size()==0);
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for projection capabilities.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -30,6 +30,8 @@ void test_projection()
employee_set_by_name::iterator it1;
employee_set_by_age::iterator it2;
employee_set_as_inserted::iterator it3;
employee_set_by_ssn::iterator it4;
employee_set_randomly::iterator it5;
BOOST_STATIC_ASSERT((boost::is_same<
employee_set::iterator,
@ -49,18 +51,33 @@ void test_projection()
BOOST_STATIC_ASSERT((boost::is_same<
employee_set_as_inserted::iterator,
nth_index_iterator<employee_set,3>::type >::value));
BOOST_STATIC_ASSERT((boost::is_same<
employee_set_by_ssn::iterator,
nth_index_iterator<employee_set,4>::type >::value));
BOOST_STATIC_ASSERT((boost::is_same<
employee_set_randomly::iterator,
nth_index_iterator<employee_set,5>::type >::value));
it= es.find(employee(1,"Robert",27,5601));
it1= project<name>(es,it);
it2= project<age>(es,it1);
it3= project<as_inserted>(es,it2);
it4= project<ssn>(es,it3);
it5= project<randomly>(es,it4);
#if defined(BOOST_NO_MEMBER_TEMPLATES)
itbis=project<0>(es,it3);
itbis=project<0>(es,it5);
#else
itbis=es.project<0>(it3);
itbis=es.project<0>(it5);
#endif
BOOST_CHECK(*it==*it1&&*it1==*it2&&*it2==*it3&&itbis==it);
BOOST_CHECK(
*it==*it1&&*it1==*it2&&*it2==*it3&&*it3==*it4&&*it4==*it5&&itbis==it);
BOOST_CHECK(project<name>(es,es.end())==get<name>(es).end());
BOOST_CHECK(project<age>(es,es.end())==get<age>(es).end());
BOOST_CHECK(project<as_inserted>(es,es.end())==get<as_inserted>(es).end());
BOOST_CHECK(project<ssn>(es,es.end())==get<ssn>(es).end());
BOOST_CHECK(project<randomly>(es,es.end())==get<randomly>(es).end());
const employee_set& ces=es;
@ -68,6 +85,8 @@ void test_projection()
employee_set_by_name::const_iterator cit1;
employee_set_by_age::const_iterator cit2;
employee_set_as_inserted::const_iterator cit3;
employee_set_by_ssn::const_iterator cit4;
employee_set_randomly::const_iterator cit5;
BOOST_STATIC_ASSERT((boost::is_same<
employee_set::const_iterator,
@ -87,10 +106,12 @@ void test_projection()
BOOST_STATIC_ASSERT((boost::is_same<
employee_set_as_inserted::const_iterator,
nth_index_const_iterator<employee_set,3>::type >::value));
BOOST_CHECK(project<name>(es,es.end())==get<name>(es).end());
BOOST_CHECK(project<age>(es,es.end())==get<age>(es).end());
BOOST_CHECK(project<as_inserted>(es,es.end())==get<as_inserted>(es).end());
BOOST_STATIC_ASSERT((boost::is_same<
employee_set_by_ssn::const_iterator,
nth_index_const_iterator<employee_set,4>::type >::value));
BOOST_STATIC_ASSERT((boost::is_same<
employee_set_randomly::const_iterator,
nth_index_const_iterator<employee_set,5>::type >::value));
cit= ces.find(employee(4,"John",57,1002));
#if defined(BOOST_NO_MEMBER_TEMPLATES)
@ -104,7 +125,11 @@ void test_projection()
#else
cit3= ces.project<as_inserted>(cit2);
#endif
citbis=project<0>(ces,cit3);
cit4= project<ssn>(ces,cit3);
cit5= project<randomly>(ces,cit4);
citbis=project<0>(ces,cit5);
BOOST_CHECK(*cit==*cit1&&*cit1==*cit2&&*cit2==*cit3&&citbis==cit);
BOOST_CHECK(
*cit==*cit1&&*cit1==*cit2&&*cit2==*cit3&&*cit3==*cit4&&*cit4==*cit5&&
citbis==cit);
}

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for serialization.
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -18,6 +18,7 @@
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <boost/noncopyable.hpp>
#include <boost/test/test_tools.hpp>
@ -199,7 +200,8 @@ void test_serialization()
int,
indexed_by<
sequenced<>,
sequenced<>
sequenced<>,
random_access<>
>
> multi_index_t;
@ -218,6 +220,7 @@ void test_serialization()
typedef multi_index_container<
int,
indexed_by<
random_access<>,
sequenced<>,
ordered_non_unique<identity<int> >
>
@ -242,6 +245,7 @@ void test_serialization()
ordered_non_unique<
BOOST_MULTI_INDEX_MEMBER(pair_of_ints,int,second)
>,
random_access<>,
sequenced<>
>
> multi_index_t;

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for replace(), modify() and modify_key().
*
* Copyright 2003-2005 Joaquín M López Muñoz.
* Copyright 2003-2006 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -23,6 +23,7 @@ void test_update()
{
employee_set es;
employee_set_as_inserted& i=get<as_inserted>(es);
employee_set_randomly& r=get<randomly>(es);
es.insert(employee(0,"Joe",31,1123));
es.insert(employee(1,"Robert",27,5601));
@ -33,12 +34,15 @@ void test_update()
employee_set::iterator it=es.find(employee(0,"Joe",31,1123));
employee_set_as_inserted::iterator it1=
project<as_inserted>(es,get<name>(es).find("Olbert"));
employee_set_randomly::iterator it2=
project<randomly>(es,get<age>(es).find(57));
BOOST_CHECK(es.replace(it,*it));
BOOST_CHECK(!es.replace(it,employee(3,"Joe",31,1123))&&it->id==0);
BOOST_CHECK(es.replace(it,employee(0,"Joe",32,1123))&&it->age==32);
BOOST_CHECK(i.replace(it1,employee(3,"Albert",20,9012))&&it1->name==
"Albert");
BOOST_CHECK(!r.replace(it2,employee(4,"John",57,5601)));
{
typedef multi_index_container<
@ -106,7 +110,7 @@ void test_update()
pair_of_ints,
indexed_by<
hashed_unique<BOOST_MULTI_INDEX_MEMBER(pair_of_ints,int,first)>,
sequenced<>,
random_access<>,
ordered_unique<BOOST_MULTI_INDEX_MEMBER(pair_of_ints,int,second)> > >
int_int_set;