diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index ecdf77e06b9..23f3b1d768c 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace CGAL { @@ -87,10 +88,10 @@ namespace internal { bool operator==( const Self& x) const { return node == x.node; } bool operator!=( const Self& x) const { return node != x.node; } - bool operator< ( const Self& x) const { return node< x.node; } - bool operator<=( const Self& x) const { return node<= x.node; } - bool operator> ( const Self& x) const { return node> x.node; } - bool operator>=( const Self& x) const { return node>= x.node; } + bool operator< ( const Self& x) const { return Get_time_stamper::type::less(node, x.node); } + bool operator<=( const Self& x) const { return Get_time_stamper::type::less(node, x.node) || node==x.node; } + bool operator> ( const Self& x) const { return Get_time_stamper::type::less(x.node, node); } + bool operator>=( const Self& x) const { return Get_time_stamper::type::less(x.node, node) || node==x.node; } T& operator*() const { return *node; } T* operator->() const { return node; } Self& operator++() { @@ -138,12 +139,12 @@ namespace internal { In_place_list_const_iterator( Iterator i) : node(&*i) {} In_place_list_const_iterator(const T* x) : node(x) {} - bool operator==( const Self& x) const { return node == x.node; } - bool operator!=( const Self& x) const { return node != x.node; } - bool operator< ( const Self& x) const { return node< x.node; } - bool operator<=( const Self& x) const { return node<= x.node; } - bool operator> ( const Self& x) const { return node> x.node; } - bool operator>=( const Self& x) const { return node>= x.node; } + bool operator==( const Self& x) const { return node == x.node; } + bool operator!=( const Self& x) const { return node != x.node; } + bool operator< ( const Self& x) const { return Get_time_stamper::type::less(node, x.node); } + bool operator<=( const Self& x) const { return Get_time_stamper::type::less(node, x.node) || node==x.node; } + bool operator> ( const Self& x) const { return Get_time_stamper::type::less(x.node, node); } + bool operator>=( const Self& x) const { return Get_time_stamper::type::less(x.node, node) || node==x.node; } const T& operator*() const { return *node; } const T* operator->() const { return node; } Self& operator++() { @@ -233,6 +234,7 @@ protected: pointer node; size_type length; + Time_stamper_impl* time_stamper_ptr; // These are the only places where the allocator gets called. pointer get_node() { pointer p = allocator.allocate(1); @@ -265,8 +267,10 @@ public: // CREATION // // New creation variable is: `l' - - explicit In_place_list() : length(0) { + explicit In_place_list() + : length(0) + , time_stamper_ptr(new Time_stamper_impl()) + { // introduces an empty list. node = get_node(); (*node).next_link = node; @@ -314,6 +318,7 @@ public: (*((*position.node).prev_link)).next_link = &x; (*position.node).prev_link = &x; ++length; + time_stamper_ptr->set_time_stamp(&x); return &x; } iterator insert(T* pos, T& x) { @@ -385,11 +390,17 @@ public: erase( iterator(first), iterator(last)); } - void clear() { erase( begin(), end()); } + void clear() { + erase( begin(), end()); + time_stamper_ptr->reset(); + } // CREATION (Continued) - explicit In_place_list(size_type n, const T& value = T()) : length(0) { + explicit In_place_list(size_type n, const T& value = T()) + : length(0) + , time_stamper_ptr(new Time_stamper_impl()) + { // introduces a list with n items, all initialized with copies of // value. node = get_node(); @@ -399,7 +410,10 @@ public: } template - In_place_list( InputIterator first, InputIterator last) : length(0) { + In_place_list( InputIterator first, InputIterator last) + : length(0) + , time_stamper_ptr(new Time_stamper_impl()) + { // a list with copies from the range [`first,last'). node = get_node(); (*node).next_link = node; @@ -407,14 +421,21 @@ public: insert( begin(), first, last); } - In_place_list(const T* first, const T* last) : length(0) { + In_place_list(const T* first, const T* last) + : length(0) + , time_stamper_ptr(new Time_stamper_impl()) + { // a list with copies from the range [`first,last'). node = get_node(); (*node).next_link = node; (*node).prev_link = node; insert(begin(), first, last); } - In_place_list(const Self& x) : length(0) { + + In_place_list(const Self& x) + : length(0) + , time_stamper_ptr(new Time_stamper_impl()) + { // copy constructor. Each item in `l1' is copied. node = get_node(); (*node).next_link = node; @@ -424,6 +445,7 @@ public: ~In_place_list() { erase(begin(), end()); put_node(node); + delete time_stamper_ptr; } Self& operator=(const Self& x); @@ -486,6 +508,8 @@ protected: public: void splice(iterator position, Self& x) { + // make sure splice is not called if time stamps are used + CGAL_static_assertion( !internal::Has_timestamp::value ); // inserts the list x before position `pos' and x becomes empty. // It takes constant time. Precondition: `&l != &x'. if (!x.empty()) { @@ -498,6 +522,8 @@ public: splice( iterator(position), x); } void splice( iterator position, Self& x, iterator i) { + // make sure splice is not called if time stamps are used + CGAL_static_assertion( !internal::Has_timestamp::value ); // inserts an element pointed to by i from list x before position // `pos' and removes the element from x. It takes constant time. i // is a valid dereferenceable iterator of x. The result is @@ -512,6 +538,8 @@ public: splice( iterator(position), x, iterator(i)); } void splice(iterator pos, Self& x, iterator first, iterator last) { + // make sure splice is not called if time stamps are used + CGAL_static_assertion( !internal::Has_timestamp::value ); // inserts elements in the range [`first, last') before position // `pos' and removes the elements from x. It takes constant time // if `&x == $l'; otherwise, it takes linear time. [`first,