Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-08-23 09:03:38


On Sat, Aug 23, 2003 at 09:45:42AM -0400, Brian McNamara wrote:
> // use boost::lamdba
> boost::lexicographic<person>
> ( _1.first, cmp_lower ) /* see below */
> ( _1.last, cmp_lower )
> ( bind(&T::age,_1) /* use default cmp */ )
> ( p1, p2 )
...
> The problem (cited "see below") is that since operator "." isn't
> overloadable, the boost::lambda expressions like "_1.first" don't
> actually exist. Offhand I dunno if C++ in general or Boost in
> particular offers a nice way to lambda-ify such a member-variable
> expression.

I just looked at the boost::lambda documentation and see that they were
clever enough to make bind() work on member variables as well as member
functions. So the actual syntax would be

   // Assume "p1.first", "p1.last", and "p1.age()" are all legal
   boost::lexicographic<person>
         ( bind(&T::first,_1), cmp_lower )
         ( bind(&T::last,_1), cmp_lower )
         ( bind(&T::age,_1) /* use default cmp */ )
     // above returns a comparator object; can add
         ( p1, p2 )
     // to call it if desired

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