R
Rui Maciel
I'm trying to go through the elements of a STL list container in such a way
that each element can be acessed along with each and every subsequent
element from the list. For example, let's say I have the following list:
A B C D E F G H...
What I am trying to do is something like this:
AB, AC, AD, AE, ... , BC, BD, BE, ... , CD, CE, ...
I tried to do that with a couple of nested for(;
loops abut I wasn't
successfull. What I tried to do was something like this....
<code>
std::list<Obj> object_list;
// populate the list with objects
for(std::list<Obj>::iterator i = object_list.begin(); i !=
object_list.end(); i++)
{
for(std::list<Obj>::iterator j = i; j != object_list.end(); j++)
{
// do stuff with i and j
}
}
</code>
That starts with i and j pointing towards the same object, which isn't good.
I've tried to use something like j++ = i but I haven't had much luck.
Finally I used a if(i == j) return; but I do not believe that this is the
best way of doing things.
So, how can I traverse this list? What is the best way of doing things?
Thanks in advace
Rui Maciel
that each element can be acessed along with each and every subsequent
element from the list. For example, let's say I have the following list:
A B C D E F G H...
What I am trying to do is something like this:
AB, AC, AD, AE, ... , BC, BD, BE, ... , CD, CE, ...
I tried to do that with a couple of nested for(;
successfull. What I tried to do was something like this....
<code>
std::list<Obj> object_list;
// populate the list with objects
for(std::list<Obj>::iterator i = object_list.begin(); i !=
object_list.end(); i++)
{
for(std::list<Obj>::iterator j = i; j != object_list.end(); j++)
{
// do stuff with i and j
}
}
</code>
That starts with i and j pointing towards the same object, which isn't good.
I've tried to use something like j++ = i but I haven't had much luck.
Finally I used a if(i == j) return; but I do not believe that this is the
best way of doing things.
So, how can I traverse this list? What is the best way of doing things?
Thanks in advace
Rui Maciel