Logo

Programming-Idioms

History of Idiom 118 > diff from v27 to v28

Edit summary for version 28 by fantasy:
New Cpp implementation by user [fantasy]

Version 27

2018-05-08, 01:41:28

Version 28

2018-05-08, 01:45:44

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Illustration

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Illustration
Imports
#include <set>
Code
std::set<T> y (x.begin (), x.end ());
Comments bubble
Assuming that x is a list of T's and T has operator<. If T is hashable, it is better to use std::unordered_set.