views:

217

answers:

3

I have browsed the documentation, but didn't find one. Any ideas?

A: 

By now I have the following:

   //filter out duplicates: stl algorithm 'unique' would be useful here
      QList<int> uniqueIDs;
      qStableSort(res);
      foreach(int id, res)
       if ( (uniqueIDs.empty()) 
                || (uniqueIDs.back() != id))
            uniqueIDs.push_back(id);
      swap(res, uniqueIDs);

res being the input for filtering, and not pleased with it.

MadH
+5  A: 

You should be able to just apply std::unique to the iterators of QList. std::unique just requires the iterators to be forward iterators (here and here), and it appears that QList's iterators meet that requirement.

blwy10
well, it also requires compiling Qt with STL support (which so far wasn't needed)
MadH
+1 but true, std::erase + std::unique should work just fine
MadH
+1  A: 

Consider using a QSet instead (and use QSet::toList when you need it as a list).

Intransigent Parsnip
set is good idea. The only reason I'm using list is that it's easier to add items (and there are thousands of them collected by a breath first search).
MadH
`mySet.insert(foo)` doesn't seem particularly hard to me.
Lukáš Lalinský
@Lukáš well it harder for the processor ...
TimW