Boost logo

Boost :

From: Marshall Clow (marshall_at_[hidden])
Date: 2003-07-10 15:51:05


At 7:21 AM -0400 7/10/03, David Abrahams wrote:
>Marshall Clow <marshall_at_[hidden]> writes:
>
> > So, here they are. Are they useful to anyone else? Is there some
>reason that
>> they don't already exist? Did I miss them somewhere?
>>
>> template <class T1, class T2>
>> struct first: std::unary_function< std::pair <T1, T2>, T1>
>> {
>> T1 operator()(const std::pair <T1, T2> & x) const { return x.first;}
>> };
>>
>> template <class T1, class T2>
>> struct first: std::unary_function< std::pair <T1, T2>, T2>
>> {
>> T2 operator()(const std::pair <T1, T2> & x) const { return x.second;}
>> };
>>
>
>The second one appears to be misnamed.

Yeah. :-(
Teach me to try to "boostify" them using an email client.

But other than that, what do people think?

I needed them because someone had a map<int, Foo*>, and I wanted to
call a member function
(call it "Bar") on each Foo* in the map. Turns out, that with
boost::compose and 'second', it
was simple:

        std::for_each ( m.begin (), m.end (),
                boost::compose_f_gx ( std::mem_fun ( Foo::Bar ),
second <int, Foo *> ()));

-- 
-- Marshall
Marshall Clow     Idio Software   <mailto:marshall_at_[hidden]>
Hey! Who messed with my anti-paranoia shot?

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