|
-
[STL Unique] regarding the duplicated elements
Question on what happens to the extra elements that are found to be duplicates. Specifically, the last sentence in the following paragraph.
http://www.sgi.com/tech/stl/unique.html
Every time a consecutive group of duplicate elements appears in the range [first, last), the algorithm unique removes all but the first element. That is, unique returns an iterator new_last such that the range [first, new_last) contains no two consecutive elements that are duplicates. [1] The iterators in the range [new_last, last) are all still dereferenceable, but the elements that they point to are unspecified.
So it's dereferenceable but you get garbage for those elements?
in SGI's example, they created new iterator.
vector<int>::iterator new_end = unique(V.begin(), V.end());
what if I reused the end() iterator?
V.end() = unique(V.begin(), V.end());
is this causing memory leak from the new end() to the old end()?
Let's say there are 10 total elements and 5 are duplicates. So according to the SGI description, the size() will still be 10 after unique. What's the preferred way to get the right size? do you always have to involve an extra erase command after unique?
Last edited by rssmps; 12-26-2005 at 05:40 AM.
Similar Threads
-
Replies: 1
Last Post: 10-31-2005, 02:04 PM
-
By J.C. Tierney in forum Enterprise
Replies: 0
Last Post: 01-14-2002, 07:32 AM
-
Replies: 5
Last Post: 08-03-2001, 01:06 PM
-
Replies: 2
Last Post: 04-30-2001, 02:27 AM
-
Replies: 1
Last Post: 01-30-2001, 12:47 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks