
Boost : 
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 20040413 04:37:04
Brian McNamara <lorgon <at> cc.gatech.edu> writes:
>
> On Wed, Apr 07, 2004 at 08:59:42PM 0400, Arkadiy Vertleyb wrote:
> > I am wonderring if there is an easy way to determine the type of a lambda
> > functor, kind of lambdaspecific typeof facility. I do realize that the
> > primary purpose of lambda is to create temporary functors to pass to STL
> > algorithms. On the other hand, there are contexts where functors need to be
> > stored, such as in std::set, etc. One might want to use Lambda to generate
> > such a functor, but without knowing its type it would be of limited use (of
> > course one can directly specify the type of such functor, but this would be
> > rather tedious).
> >
> > Has anything been done by anybody in this regard?
>
> I don't know that Lambda has anything like this. FC++ does:
>
> http://www.cc.gatech.edu/~yannis/fc++/boostpaper/fcpp.sectlambda.html#id270886
>
I think the possibility of having the type of a lambda expression
is extremely interesting. IMHO, this facility can be conceptualized
as a "static lambda" library. Let me ellaborate:
Consider std::sort. This function takes an extra functor in
charge of doing the comparison work, for which Boost.Lambda
nicely fits the bill:
std::sort(it0,it1,_1<_2); // trivial comparison.
std::set, OTOH, also takes a comparison predicate, though
this is commonly passed by type rather than as an expression:
std::set<int,std::less<int> >
Here, we can consider std::less as the static version
of _1<_2, with the difference that the <int> has to be
explicitly stated. Generally speaking, a given class template T
is the static version of a lambda expression expr if
T<Arg1,...Argn>()(arg1,...,argn) is the same as expr(arg1,...,argn)
for argi of type Argi.
So it would be nice if Boost.Lambda is augmented with
more or less comfortable syntax to produce static
lambda types. I'm thinking of having something as
namespace sl=boost::lambda::static;
std::set<
int,
sl::less<sl::_1,sl::_2>::type // equivalent to _1<_2
<int,int> // instantiated for int types
>;
std::set<
int*,
sl::less<
sl::deref<sl::_1>, // eq. to *_1<*_2
sl::deref<sl::_2>
>::type
<int*,int*> // instantiated for int*
>;
Maybe this is quite a lot of work, but IMHO the
potential of it is great. I don't know wheter
MPL has already the possibility of doing something
like this (I guess it doesn't), or on the contrary this
static lambda library can be regarded as a cooperative
addon to MPL. Comments?
JoaquÃn M LÃ³pez MuÃ±oz
TelefÃ³nica, InvestigaciÃ³n y Desarrollo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk