At 7:21 AM -0400 7/10/03, David Abrahams wrote:Marshall Clow <[EMAIL PROTECTED]> writes:But other than that, what do people think?
> So, here they are. Are they useful to anyone else? Is there some reason thatthey 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;}
};
I would prefer "select_nth".
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 *> ()));
How about:
std::for_each(m.begin(), m.end(),
boost::compose_f_gx(std::mem_fun(Foo::Bar), select_nth<1, std::pair<int, Foo*> >()));
See http://www.cs.umu.se/~ens01dwn/select_nth.hpp for a sample implementation that handles boost::tuples and pairs.
--- Daniel Wallin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost