From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-07-12 15:43:50
On Sat, Jul 12, 2003 at 01:21:49PM +0100, Andy Sawyer wrote:
> There's a third form I've also found useful on occasion:
> struct selector1st
> template<typename Pair>
> const typename Pair::first_type& operator()( const Pair& a ) const
> return a.first;
> Which has the advantage of not needing to specify _any_ type at the call
> for_each( map.begin(), map.end(), selector1st() );
> And again, is not limited to use with std::pair. However, it's utility
> is limited by not inheriting from std::unary_function.
If and when I get FC++ ( http://www.cc.gatech.edu/~yannis/fc++/ ) into
Boost, FC++ has the same kind of selectors you've shown above (named
"fst" and "snd", as in Haskell). Whereas these function objects also
cannot be used with STL algorithms requiring adaptables (for the reason
you mention above), it can be used with the analogous algorithms in
FC++, since the FC++ infrastructure enables return-type-deduction for
template function objects.
I've been working on "boostifying" FC++ this past week (adopting naming
conventions, reusing Boost code, etc.) and will hopefully get a
Boost-ful FC++ version up for review in the next two weeks or so.
-- -Brian McNamara (lorgon_at_[hidden])
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk