Changes introduced by the new intrusive version.

[SVN r39550]
This commit is contained in:
Ion Gaztañaga
2007-09-26 17:38:32 +00:00
parent cbb4812c00
commit c4aa57001c
32 changed files with 2259 additions and 1025 deletions
+10 -14
View File
@@ -14,9 +14,10 @@
#include <iostream>
#include <vector>
using namespace boost::intrusive;
//A class that can be inserted in an intrusive list
class my_class
: public boost::intrusive::list_base_hook<>
class my_class : public list_base_hook<>
{
public:
friend bool operator==(const my_class &a, const my_class &b)
@@ -28,20 +29,18 @@ class my_class
};
//Definition of the intrusive list
typedef boost::intrusive::list< my_class::value_traits<my_class> > my_class_list;
typedef list<my_class> my_class_list;
//Cloner object function
class new_cloner
struct new_cloner
{
public:
my_class *operator()(const my_class &clone_this)
{ return new my_class(clone_this); }
};
//The disposer object function
class delete_disposer
struct delete_disposer
{
public:
void operator()(my_class *delete_this)
{ delete delete_this; }
};
@@ -54,9 +53,8 @@ int main()
//Fill all the nodes and insert them in the list
my_class_list list;
for(int i = 0; i < MaxElem; ++i){
nodes[i].int_ = i;
}
for(int i = 0; i < MaxElem; ++i) nodes[i].int_ = i;
list.insert(list.end(), nodes.begin(), nodes.end());
//Now clone "list" using "new" and "delete" object functions
@@ -64,12 +62,10 @@ int main()
cloned_list.clone_from(list, new_cloner(), delete_disposer());
//Test that both are equal
if(cloned_list != list){
if(cloned_list != list)
std::cout << "Both lists are different" << std::endl;
}
else{
else
std::cout << "Both lists are equal" << std::endl;
}
//Don't forget to free the memory from the second list
cloned_list.clear_and_dispose(delete_disposer());