mirror of
https://github.com/boostorg/intrusive.git
synced 2026-04-28 18:02:04 +02:00
Changes introduced by the new intrusive version.
[SVN r39550]
This commit is contained in:
+17
-31
@@ -15,7 +15,7 @@
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
class MyClass : public list_base_hook<> //This is a derivation hook
|
||||
class MyClass : public list_base_hook<> //This is a derivation hook
|
||||
{
|
||||
int int_;
|
||||
|
||||
@@ -26,63 +26,49 @@ class MyClass : public list_base_hook<> //This is a derivation hook
|
||||
MyClass(int i)
|
||||
: int_(i)
|
||||
{}
|
||||
|
||||
int get() const
|
||||
{ return int_; }
|
||||
};
|
||||
|
||||
//Define a list that will store MyClass using the public base hook
|
||||
typedef list< list_base_hook<>::value_traits<MyClass> > BaseList;
|
||||
typedef list<MyClass> BaseList;
|
||||
|
||||
//Define a list that will store MyClass using the public member hook
|
||||
typedef list< list_member_hook<>::value_traits<MyClass, &MyClass::member_hook_> > MemberList;
|
||||
typedef list< MyClass
|
||||
, member_hook< MyClass, list_member_hook<>, &MyClass::member_hook_>
|
||||
> MemberList;
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::vector<MyClass> Vect;
|
||||
typedef Vect::iterator VectIt;
|
||||
typedef Vect::reverse_iterator VectRit;
|
||||
typedef std::vector<MyClass>::iterator VectIt;
|
||||
typedef std::vector<MyClass>::reverse_iterator VectRit;
|
||||
|
||||
//Create several MyClass objects, each one
|
||||
//with a different internal number
|
||||
Vect myclassvector;
|
||||
for(int i = 0; i < 100; ++i)
|
||||
myclassvector.push_back(MyClass(i));
|
||||
//Create several MyClass objects, each one with a different value
|
||||
std::vector<MyClass> values;
|
||||
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
|
||||
|
||||
BaseList baselist;
|
||||
MemberList memberlist;
|
||||
|
||||
//Now insert them in the reverse order
|
||||
//in the base hook intrusive list
|
||||
for(VectIt it(myclassvector.begin()), itend(myclassvector.end())
|
||||
; it != itend
|
||||
; ++it){
|
||||
//Now insert them in the reverse order in the base hook list
|
||||
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
|
||||
baselist.push_front(*it);
|
||||
}
|
||||
|
||||
//Now insert them in the same order as in vector in the
|
||||
//member hook intrusive list
|
||||
for(VectIt it(myclassvector.begin()), itend(myclassvector.end())
|
||||
; it != itend
|
||||
; ++it){
|
||||
//Now insert them in the same order as in vector in the member hook list
|
||||
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
|
||||
memberlist.push_back(*it);
|
||||
}
|
||||
|
||||
//Now test lists
|
||||
{
|
||||
BaseList::reverse_iterator rbit(baselist.rbegin()), rbitend(baselist.rend());
|
||||
MemberList::iterator mit(memberlist.begin()), mitend(memberlist.end());
|
||||
VectIt it(myclassvector.begin()), itend(myclassvector.end());
|
||||
VectIt it(values.begin()), itend(values.end());
|
||||
|
||||
//Test the objects inserted in the base hook list
|
||||
for(; it != itend; ++it, ++rbit){
|
||||
for(; it != itend; ++it, ++rbit)
|
||||
if(&*rbit != &*it) return 1;
|
||||
}
|
||||
|
||||
//Test the objects inserted in the member hook list
|
||||
for(it = myclassvector.begin(); it != itend; ++it, ++mit){
|
||||
for(it = values.begin(); it != itend; ++it, ++mit)
|
||||
if(&*mit != &*it) return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user