Boost logo

Boost :

From: Marshall Clow (marshall_at_[hidden])
Date: 2003-07-09 19:32:06


I recently had a need for a functor to return a component of a
std::pair, and I was
surprised to see that they didn't exist either in the standard
library or in boost.

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;}
};

-- 
-- 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