From fd4996ab4ab83bc09afb109e57889c42867408a0 Mon Sep 17 00:00:00 2001 From: AlexanderMisel Date: Sun, 11 May 2014 23:12:31 +0800 Subject: [PATCH] std::list::unique added ^_^ --- bld/hdr/watcom/list.mh | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/bld/hdr/watcom/list.mh b/bld/hdr/watcom/list.mh index 6d2ee33f70..a66576a3a8 100644 --- a/bld/hdr/watcom/list.mh +++ b/bld/hdr/watcom/list.mh @@ -205,7 +205,29 @@ namespace std { void splice( iterator it, list &other, iterator first, iterator last ); void reverse( ); + void unique( ); void merge( list &other ); + + template< class BinaryPredicate > + void unique( BinaryPredicate pred ) + { + iterator first( begin( ) ); + iterator last ( end( ) ); + + if ( first == last ) + return; + + iterator next( first ); + + while ( !(++next == last) ) + { + if ( pred( *first, *next ) ) + erase( next ); + else + first = next; + next = first; + } + } // sort( ) // ******* @@ -1022,6 +1044,29 @@ namespace std { sentinel->previous = temp; } + // unique( ) + // ********** + template< class Type, class Allocator > + void list< Type, Allocator >::unique( ) + { + iterator first( begin( ) ); + iterator last ( end( ) ); + + if ( first == last ) + return; + + iterator next( first ); + + while ( !(++next == last) ) + { + if ( *first == *next ) + erase( next ); + else + first = next; + next = first; + } + } + // merge( list & ) // *************** template< class Type, class Allocator >