Commit 1bb16ad6 authored by Tobias Hunger's avatar Tobias Hunger

Algorithm: Add filteredUnique

This methods returns a new container with only the unique elements
in the input container. Uses == for comparison of elements.

Change-Id: I80c2027b4d275d27343bd64851c17d42bc971e82
Reviewed-by: default avatarEike Ziller <>
parent f7d8d97e
......@@ -394,6 +394,31 @@ std::tuple<C, C> partition(const C &container, R (S::*predicate)() const)
return partition(container, std::mem_fn(predicate));
// filteredUnique
template<typename C>
C filteredUnique(const C &container)
C result;
auto ins = inserter(result);
QSet<typename C::value_type> seen;
int setSize = 0;
auto endIt = container.end();
for (auto it = container.begin(); it != endIt; ++it) {
if (setSize == seen.size()) // unchanged size => was already seen
ins = *it;
return result;
// sort
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment