Logo

Programming-Idioms

History of Idiom 119 > diff from v52 to v53

Edit summary for version 53 by arouene:
New Cpp implementation by user [arouene]

Version 52

2019-02-06, 12:10:10

Version 53

2019-09-26, 18:29:25

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration
Extra Keywords
deduplicate dupe dupes redundant redundancy undupe
Extra Keywords
deduplicate dupe dupes redundant redundancy undupe
Imports
#include <algorithm>
#include <vector>
Code
std::sort(x.begin(), x.end());
auto last = std::unique(x.begin(), x.end());
x.erase(last, x.end());
Comments bubble
List x must be a STL container like a std::vector.
Doc URL
https://en.cppreference.com/w/cpp/algorithm/unique
Demo URL
http://cpp.sh/4thnn