I have a stl set of integers, and I would like to iterate over all unique pairs of integer values, where by uniqueness I consider val1, val2 and val2, val1 to be the same, and I should see this combination once.
I wrote this in python, where I use list index (clusters):
for i in range(len(clusters) - 1): for j in range(i+1,len(clusters)):
but without an index, I'm not sure how I can achieve the same with a set of stl and iterators. I tried:
for (set<int>::iterator itr = myset.begin(); itr != myset.end()-1; ++itr) { cout << *itr; }
but this is not so, since the iterator does not have the operator a.
How can I achieve this or use a different container?
zenna source share