Re: [Boost-users] erase and iterators

boost-users-bounces@lists.boost.org wrote:
On Tue, Jul 11, 2006 at 10:19:05AM +0000, Roman Neuhauser wrote:
# kneeride@gmail.com / 2006-07-11 17:31:23 +1000:
On 7/11/06, Michael Nicolella
wrote: vec.erase( std::remove_if( vec.begin(), vec.end(), some_condition_functor ) );
Mike, I do like your remove_if example.
i am not familar with this approach, can you please give me an example of defining a some_condition_functor? for example when the value == 5.
What about this?
Let's assume the vector contains ints
class condition_functor {
public:
bool operator()(int elem) { return elem==5 } };
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
you can use Boost.Lambda for this
#include

On 7/11/06, David Klein
boost-users-bounces@lists.boost.org wrote:
On Tue, Jul 11, 2006 at 10:19:05AM +0000, Roman Neuhauser wrote:
# kneeride@gmail.com / 2006-07-11 17:31:23 +1000:
On 7/11/06, Michael Nicolella
wrote: vec.erase( std::remove_if( vec.begin(), vec.end(), some_condition_functor ) );
Mike, I do like your remove_if example.
i am not familar with this approach, can you please give me an example of defining a some_condition_functor? for example when the value == 5.
What about this?
Let's assume the vector contains ints
class condition_functor {
public:
bool operator()(int elem) { return elem==5 } };
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
you can use Boost.Lambda for this
#include
using namespace boost::lambda;
std::vector<int> v; ... v.erase(std::remove_if(v.begin(), v.end(), 5 == _1));
-- HTH dave _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
maybe i'm old school but i don't like those crazy constructs. i like a mix between OO and functional. **i'm even still getting used to the erase(remove_if()) syntax ;)

On 7/11/06, David Klein
you can use Boost.Lambda for this
#include
using namespace boost::lambda;
std::vector<int> v; ... v.erase(std::remove_if(v.begin(), v.end(), 5 == _1));
Shouldn't it be v.erase( std::remove_if(v.begin(), v.end(), 5 == _1), v.end() ); as you want to erase the range, not just the single element? ~ SWMc
participants (3)
-
bringiton bringiton
-
David Klein
-
me22