1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2013
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
13 #include <boost/intrusive/list.hpp>
16 using namespace boost::intrusive;
18 class MyClass : public list_base_hook<> //This is a derivation hook
23 //This is a member hook
24 list_member_hook<> member_hook_;
31 //Define a list that will store MyClass using the public base hook
32 typedef list<MyClass> BaseList;
34 //Define a list that will store MyClass using the public member hook
36 , member_hook< MyClass, list_member_hook<>, &MyClass::member_hook_>
41 typedef std::vector<MyClass>::iterator VectIt;
43 //Create several MyClass objects, each one with a different value
44 std::vector<MyClass> values;
45 for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
48 MemberList memberlist;
50 //Now insert them in the reverse order in the base hook list
51 for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
52 baselist.push_front(*it);
54 //Now insert them in the same order as in vector in the member hook list
55 for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it)
56 memberlist.push_back(*it);
60 BaseList::reverse_iterator rbit(baselist.rbegin());
61 MemberList::iterator mit(memberlist.begin());
62 VectIt it(values.begin()), itend(values.end());
64 //Test the objects inserted in the base hook list
65 for(; it != itend; ++it, ++rbit)
66 if(&*rbit != &*it) return 1;
68 //Test the objects inserted in the member hook list
69 for(it = values.begin(); it != itend; ++it, ++mit)
70 if(&*mit != &*it) return 1;