|
Boost Users : |
Subject: Re: [Boost-users] Foreach For iterating two containers
From: Gokulakannan Somasundaram (gokul007_at_[hidden])
Date: 2010-02-21 09:54:06
Sorry the construct is like this
std::vector<int>::iterator iter1;
std::vector<std::string>::iterator iter2;
for( iter1 = cont1->begin(), iter2 = cont2->begin();
iter1 != cont1->end() *&&* iter2 != cont2->end(); ++iter1,
++iter2 )
{
int x = *iter1;
std::string y = *iter2;
.....
}
I have change the || into &&.
Thanks,
Gokul
On Sun, Feb 21, 2010 at 8:20 PM, Gokulakannan Somasundaram <
gokul007_at_[hidden]> wrote:
> Hi,
> Is it possible to use Boost Foreach to iterate over two containers
> simultaneously? I have done my preliminary search in the lists and i
> couldn't find a solution. I am asking for a solution to iteration like this
>
> std::vector<int>::iterator iter1;
> std::vector<std::string>::iterator iter2;
>
> for( iter1 = cont1->begin(), iter2 = cont2->begin();
> iter1 != cont1->end() || iter2 != cont2->end(); ++iter1,
> ++iter2 )
> {
> int x = *iter1;
> std::string y = *iter2;
>
> .....
> }
>
> If this is not present, please consider this as a feature request. The
> syntax below can also be considered
>
> forboth( int x, std::string y, cont1, cont2 )
> {
> }
>
>
> Thanks,
> Gokul.
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net