I am working with a lot of lists, and have started taking advantag of QtConcurrency, which is really great. However for some things I am not sure whether my solution is optimal (or I now that its not).

Situation 1: Removing duplicates in a Qlist:

naive approach:
Qt Code:
  1. template <typename T >
  2. void removeDuplicates(QList<*T> list)
  3. {
  4. QList<*T> copylist;
  5. foreach(T *p, list)
  6. if (!copylist.contains(p))
  7. copylist += p;
  8. list = copylist;
  9. }
To copy to clipboard, switch view to plain text mode 

What I thought would work, but does not:
Qt Code:
  1. template <typename T >
  2. void removeDuplicates(QList<*T> list)
  3. {
  4. qSort(list.begin(), list.end(), T::LessThan); // sort
  5. T* last = 0;
  6. foreach(T* current, list) // go through list and mark duplicates
  7. {
  8. if (current == last)
  9. current = 0; //mark vor removal
  10. else
  11. last = current;
  12. }
  13. list.removeAll(0);
  14. }
To copy to clipboard, switch view to plain text mode 
(the last line could also be replaced with
Qt Code:
  1. QtConcurrent::blockingFilter(list, FilterOps::uneq0<T>);
To copy to clipboard, switch view to plain text mode 
where uneq0 just checks if the ptr is null or not. Even that seems suboptimal, since the sorting is single-threaded... What do you think is best here?


Another situation is, where I want to remove from one list all elements that are also member in another list. I did it like this:
Qt Code:
  1. QtConcurrent::blockingFilter(firstList, NotIn(otherList));
  2.  
  3. // in some other place
  4. struct NotIn
  5. {
  6. QPortList compare;
  7. NotIn(const QPortList& list)
  8. : compare(list) {}
  9.  
  10. typedef bool result_type;
  11.  
  12. bool operator()(QBsdPort* port)
  13. {
  14. return !compare.contains(port);
  15. }
  16. };
To copy to clipboard, switch view to plain text mode 
Is that really the most efficient way of doing it?

Thank you for you help!