The In_place_list<T,bool> manages the items in place, i.e., inserted items are not copied. Two pointers of type T* are expected to be reserved in T for the list management. The base class In_place_list_base<T> can be used to obtain such pointers.
The In_place_list<T,bool> does not copy element items during insertion (unless otherwise stated for a function). On removal of an item or destruction of the list the items are not deleted by default. The second template parameter bool is set to false in this case. If the In_place_list<T,bool> should take the responsibility for the stored objects the bool parameter could be set to true, in which case the list will delete removed items and will delete all remaining items on destruction. In any case, the destroy() member function deletes all items. Note that these two possible versions of In_place_list<T,bool> are not assignable to each other to avoid confusions between the different storage responsibilities.
#include <CGAL/In_place_list.h>
The full class name is In_place_list<T, bool managed = false, class Alloc = CGAL_ALLOCATOR(T)>.
The parameter T is supposed to have a default constructor, a copy constructor and an assignment operator. The copy constructor and the assignment may copy the pointers in T for the list management, but they do not have to. The equality test and the relational order require the operators == and < for respectively. These operators must not compare the pointers in T.
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
| |
introduces an empty list.
| |
| |
copy constructor.
Each item in l1 is copied.
| |
| |
introduces a list with items, all initialized with copies
of .
| |
| |
| |
a list with copies from
the range [first,last).
| |
| |
non-member-template version.
|
| ||
| assignment. Each item in l1 is copied. Each item in l is deleted if the bool parameter is true. | |
|
| swaps the contents of l with l1. |
|
| all items in l are deleted regardless of the bool parameter. |
|
| test for equality: Two lists are equal, iff they have the same size and if their corresponding elements are equal. |
|
| compares in lexicographical order. |
As long as member templates are not supported, member functions using T* instead of the general InputIterator are provided.
|
| removes the first item from list l. |
|
| removes the last item from list l. |
|
| |
removes the item from list l, where pos refers to. | ||
|
| removes the item from list l, where pos refers to. |
|
| |
|
| |
removes the items in the range [first, last) from l. |
|
| |||
|
| |||
inserts the list before position pos and
becomes empty. It takes constant time. Precondition: & l!= &x. | ||||
|
| |||
|
| |||
inserts an element pointed to by from list before position pos and removes the element from . It takes constant time. is a valid dereferenceable iterator of . The result is unchanged if pos == i or pos == ++i. | ||||
|
| |||
|
| |||
inserts elements in the range [first, last) before position pos and removes the elements
from . It takes constant time if &x == &l;
otherwise, it takes linear time. [first, last) is a
valid range in . Precondition: pos is not in the range [first, last). | ||||
|
| |||
erases all elements in
the list l for which e == value. It is stable. Precondition: a suitable operator== for the type . | ||||
|
|
erases all but the first element from
every consecutive group of equal elements in the list l. Precondition: a suitable operator== for the type . | ||
|
|
merges the list
into the list l and becomes empty. It is stable. Precondition: Both lists are increasingly sorted. A suitable operator< for the type . | ||
|
| reverses the order of the elements in l in linear time. | ||
|
|
sorts the list l according to the
operator< in time log where n = size(). It is stable. Precondition: a suitable operator< for the type . |
// in_place_list_prog.C // ------------------------------- #include <CGAL/basic.h> #include <cassert> #include <algorithm> #include <CGAL/In_place_list.h> using CGAL::In_place_list_base; struct item : public In_place_list_base<item> { int key; item() {} item( const item& i) : In_place_list_base<item>(i), key(i.key) {} item( int i) : key(i) {} bool operator== (const item& i) const { return key == i.key;} bool operator!= (const item& i) const { return ! (*this == i);} bool operator== (int i) const { return key == i;} bool operator!= (int i) const { return ! (*this == i);} bool operator< (const item& i) const { return key < i.key;} }; int main() { typedef CGAL::In_place_list<item,true> List; List l; item* p = new item(1); l.push_back(*p); l.push_back(*new item(2)); l.push_front(*new item(3)); l.push_front(*new item(4)); l.push_front(*new item(2)); List::iterator i = l.begin(); ++i; l.insert(i, *new item(5)); l.insert(p, *new item(5)); int a[7] = {2,5,4,3,5,1,2}; bool ok = std::equal(l.begin(), l.end(), a); assert(ok); l.sort(); l.unique(); assert(l.size() == 5); int b[5] = {1,2,3,4,5}; ok = std::equal(l.begin(), l.end(), b); assert(ok); return 0; }