Created
January 29, 2013 03:01
-
-
Save pmelanson/4661401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <boost/intrusive/list.hpp> | |
using namespace std; | |
class entity_c : public boost::intrusive::list_base_hook<> { | |
public: | |
const int isconst; | |
int notconst; | |
entity_c(int con, int notcon) | |
: isconst(con), notconst(notcon) { | |
cout << "constructed entity (" << isconst << ',' << notconst << ")\n"; | |
} | |
~entity_c() { | |
cout << "destructed entity (" << isconst << ',' << notconst << ")\n"; | |
} | |
}; | |
typedef boost::intrusive::list<entity_c> list_t; | |
namespace {list_t global_list;} | |
//Cloner object function | |
struct new_cloner { | |
entity_c *operator()(const entity_c &clone_this) | |
{ return new entity_c(clone_this); } | |
}; | |
//The disposer object function | |
struct delete_disposer { | |
void operator()(entity_c *delete_this) | |
{ delete delete_this; } | |
}; | |
int main() { | |
int max = 5; | |
static vector<entity_c> values; | |
values.reserve(max); | |
int i = 1; | |
while(i != max) { | |
values.push_back(entity_c(i,i)); | |
cout << "MADE " << values.back().isconst << "\n\n"; | |
i++; | |
} | |
cout << "ALL CONSTRUCTED\n\n\n"; | |
static list_t list; | |
cout << "INSERT INTO BASE HOOK LIST\n"; | |
list.insert(list.begin(), values.begin(), values.end()); | |
global_list.clone_from(list, new_cloner(), delete_disposer()); | |
cout << global_list.back().isconst; //check that the back of the global list is the same back as the local list | |
cout << list.back().isconst << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment