Boost logo

Boost :

Subject: Re: [boost] [functional] New functor adaptors
From: Tigran Hayrapetyan (tigran.human_at_[hidden])
Date: 2013-09-12 15:27:55


On Thu, Sep 12, 2013 at 4:52 PM, Jonathan Wakely
<jwakely.boost_at_[hidden]>wrote:

> On 12 September 2013 13:03, Tigran Hayrapetyan wrote:
> > Hello,
> >
> > Suppose we want to transform sequence of integers by doubling and adding
> 5
> > to each value (x = 2*x + 5 for all x in sequence). If using
> std::transform,
> > then we need a functor which will for given "x" return "2*x + 5". My
> > question is - is it possible to do it in C++98 style (without lambda
> > expressions), and without writing additional functor class?
>
> std::transform(begin, end, out,
> boost::bind( std::plus<int>(), 5,
> boost::bind( std::multiplies<int>(), 2, _1 ) ) );
>
> > As I understand, it's not. For doing that we need something like nesting
> > functors into each other. Here we have "std::bind2nd(
> > std::multiplies<int>(), 2 )" functor, and "std::bind2nd(
> std::plus<int>(),
> > 5 )" functor, which must be nested to provide necessary functionality.
>
> So don't use std::bind2nd, use boost::bind which is superior in every way.
>
> Thanks for your answers. I see it now.

> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk