Boost logo

Boost Users :

From: Josue Gomes (josue.gomes.honeypot_at_[hidden])
Date: 2005-12-13 11:10:09


On 12/13/05, Peter Dimov <pdimov_at_[hidden]> wrote:
>
> Are you sure that you want this, even if it did compile? If you apply
> remove_if+transform_iterator on:
>
> A, 2
> B, 3
> C, 4
> D, 15
> E, 16
> F, 17
>
> you'll get
>
> A, 15
> B, 16
> C, 17
> D, --
> E, --
> F, --
>
> where -- denotes an unspeficied value.
>

I was not aware of this. Thanks for pointing out.

> If this is the desired result, try
>
> struct to_num
> {
> typedef int & result_type;
>
> int & operator()(std::pair<std::string, int>& p) const
> {
> return p.second;
> }
> };
>
> If, on the other hand, you want
>
> D, 15
> E, 16
> F, 17
> --, --
> --, --
> --, --
>
> you don't need transform_iterator at all:
>
> std::remove_if( c.begin(), c.end(),
>
> boost::bind( std::less_equal<int>(), boost::bind( to_num(), _1 ), 10 )
>
> );
>

Thanks. I'm already using this way. I was just wondering if it was possible to
use transform_iterator and avoid the functor.

Regards,
Josue Gomes


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