Question: Suppose I have a sorted vector without duplicated values. If I want to go through all the triples of different values, I do this:

```
for(std::size_t i = 0; i < data.size(); ++i)
  for(std::size_t j = i+1; j < data.size(); ++j)
    for(std::size_t k = j+1; k < data.size(); ++k)
      do_somthing_with(data[i],data[j],data[k]);

```

**How can I do that with iterators if my container is a `std::set` ?**

*Note: I don't use C++11 for compatibility reasons.*

Answer: 
This is a special case of choosing all k-combinations out of a set of n elements. 

See here for an explanation: <https://en.wikipedia.org/wiki/Combination> 

And this has been answered on stackoverflow before here:
[creating all possible k combinations of n items in C++](https://stackoverflow.com/questions/12991758/creating-all-possible-k-combinations-of-n-items-in-c)
You could create a vector from it and then do it the way you usually do it.

```
std::set<int> s = {1, 2, 3, 4, 5, 6, 7};
std::vector<int> data(s.begin(), s.end());
for(std::size_t i = 0; i < data.size(); ++i)
  for(std::size_t j = i+1; j < data.size(); ++j)
    for(std::size_t k = j+1; k < data.size(); ++k)
      do_somthing_with(data[i],data[j],data[k]);

```