Hi Roel.
Can't comment on the 'boost' libs but I know the following method works
normally:
-----8<-----
std::vector<int> vec; // your vector of integers
bool SmallerThan5( int value )
{
return (value<5);
}
// fill vector
// Remove elements satisfying predicate SmallerThan5 and
// use 'erase' to change(/update) the sequence size.
vec.erase( remove_if(vec.begin(),vec.end(),SmallerThan5), vec.end() );
-----8<-----
Hope that helps.
Regards,
~TJ
> Now that we're on the subject of stl algorithms, I have this question:
> I've been looking for the most stl-ish way to remove elements that
> fulfill a certain condition from a vector. I thought this would work:
>
> struct SmallerThan5
> {
> bool operator()(int i)
> {
> return i < 5;
> }
> }
> std::vector vec;
> // fill vec with a bunch of value
> vec.erase(std::find(vec.begin(), vec.end(), SmallerThan5()));
>
> ... but this only removes the first value, because the version of erase
> that takes 1 iterator only removes the element the iterator points to.
> Is there a one-line way? Oh and how would I in-line the SmallerThan5
> class with boost::lambda or boost::bind? Is it possible at all? Thanks.
_______________________________________________
msvc mailing list
[EMAIL PROTECTED]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription
changes, and list archive.