jeudi 22 janvier 2015

better way of counting unique item

I just find a way to count that number of unique items in a vector. This is my most naïve approach.



std::vector<Items> v;

// some other work
std::vector<Items> unique_Count;
unique_Count.clear();
std::unique_copy(v.begin, v.end(), std::back_inserter(unique_Count);
int uniqueCount = unique_Count.size();


Is this the only with or this there a better way in the standard library?


Aucun commentaire:

Enregistrer un commentaire