summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/intrusive/example/doc_entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/intrusive/example/doc_entity.cpp')
-rw-r--r--src/boost/libs/intrusive/example/doc_entity.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/boost/libs/intrusive/example/doc_entity.cpp b/src/boost/libs/intrusive/example/doc_entity.cpp
new file mode 100644
index 00000000..531f2294
--- /dev/null
+++ b/src/boost/libs/intrusive/example/doc_entity.cpp
@@ -0,0 +1,60 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2013
+//
+// 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)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+//[doc_entity_code
+#include <boost/intrusive/list.hpp>
+
+using namespace boost::intrusive;
+
+//A class that can be inserted in an intrusive list
+class entity : public list_base_hook<>
+{
+ public:
+ virtual ~entity();
+ //...
+};
+
+//"some_entity" derives from "entity"
+class some_entity : public entity
+{/**/};
+
+//Definition of the intrusive list
+struct entity_list : list<entity>
+{
+ ~entity_list()
+ {
+ // entity's destructor removes itself from the global list implicitly
+ while (!this->empty())
+ delete &this->front();
+ }
+};
+
+//A global list
+entity_list global_list;
+
+//The destructor removes itself from the global list
+entity::~entity()
+{ global_list.erase(entity_list::s_iterator_to(*this)); }
+
+//Function to insert a new "some_entity" in the global list
+void insert_some_entity()
+{ global_list.push_back (*new some_entity(/*...*/)); }
+
+int main()
+{
+ //Insert some new entities
+ insert_some_entity();
+ insert_some_entity();
+ //global_list's destructor will free objects
+ return 0;
+}
+
+//]