|
Boost Users : |
From: Christian Henning (chhenning_at_[hidden])
Date: 2006-03-03 13:41:29
This is most likely not the best solution but it does the work. Please
see the comment how the keys should be organized (sorted and no
doubles). The algorithm will erase values starting with the biggest
keys.
typedef std::vector<float> tFloatVector;
tFloatVector aFloatVec;
void erase( int nKey )
{
if( nKey < aFloatVec.size() )
{
tFloatVector::iterator iFloatVec = aFloatVec.begin();
iFloatVec += nKey - 1;
if( iFloatVec != aFloatVec.end() )
aFloatVec.erase( iFloatVec );
}
}
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::vector<int> tIntVector;
// assuming int's are sorted small to big
// and there are no doubles.
tIntVector aIntVec;
aIntVec.push_back( 1 );
aIntVec.push_back( 3 );
aIntVec.push_back( 4 );
aIntVec.push_back( 5 );
aFloatVec.push_back( 1.0F );
aFloatVec.push_back( 2.0F );
aFloatVec.push_back( 3.0F );
aFloatVec.push_back( 4.0F );
aFloatVec.push_back( 5.0F );
aFloatVec.push_back( 6.0F );
aFloatVec.push_back( 7.0F );
aFloatVec.push_back( 8.0F );
std::reverse( aIntVec.begin(), aIntVec.end() );
std::for_each( aIntVec.begin(), aIntVec.end(), boost::bind( &erase, _1 ) );
}
Would be interesting to see how the boost expert would solve the problem. ;-)
Christian
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