Boost logo

Boost Users :

From: Steven E. Harris (seharris_at_[hidden])
Date: 2002-08-07 13:27:43


Douglas Gregor <gregod_at_[hidden]> writes:

> Boost.Bind can do that:
>
> for_each(my_map.begin(), my_map.end(),
> bind(&Point::Reset,
> bind(&map<int, Point *>::value_type::second, _1)));
>
> So can Boost.Lambda:
>
> for_each(my_map.begin(), my_map.end(),
> bind(&Point::Reset,
> (&_1)->*&map<int, Point *>::value_type::second));

Again, I can't see how this can work. "second" is the name of a
member, not a function. You need a "pair select functor" to grab the
first or second member from a pair. I've written a couple of these to
use in conjunction with the projection_iterator adaptor.

template <class P>
struct select_pair_first
    : public std::unary_function<P, P::first_type>
{
    inline result_type& operator()(argument_type& arg) const
    { return arg.first; }

    inline const result_type& operator()(const argument_type& arg) const
    { return arg.first; }
};

template <class P>
struct select_pair_second
    : public std::unary_function<P, P::second_type>
{
    inline result_type& operator()(argument_type& arg) const
    { return arg.second; }

    inline const result_type& operator()(const argument_type& arg) const
    { return arg.second; }
};

-- 
Steven E. Harris        :: seharris_at_[hidden]
Raytheon                :: http://www.raytheon.com

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