Boost logo

Boost Users :

Subject: [Boost-users] Foreach For iterating two containers
From: Gokulakannan Somasundaram (gokul007_at_[hidden])
Date: 2010-02-21 09:50:38


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