Logo

Programming-Idioms

History of Idiom 119 > diff from v53 to v54

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

Version 53

2019-09-26, 18:29:25

Version 54

2019-09-26, 18:46:27

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 <string>
#include <unordered_set>
#include <vector>
Code
std::vector<std::string> x = {"one", "two", "two", "one", "three"};
std::unordered_set<std::string> t;
for (auto e : x)
    t.insert(e);
Comments bubble
Original order is lost.
t contains the new list of unique objects.
Demo URL
http://cpp.sh/9vvrg