Boost logo

Boost :

Subject: Re: [boost] painless currying
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-08-31 16:09:30


On 8/23/2011 3:38 PM, Eric Niebler wrote:
> After playing around with functional languages, I've come to envy how
> easy they make it to curry functions. Call a 2-argument function with 1
> argument and you get a function that takes 1 argument. Pass another
> argument and it evaluates the function. Simple. In contrast, C++ users
> have to use binders, which are not as nice.
>
> On a lark, I implemented a wrapper that turns any TR1-style function
> object into a "curryable" function object (attached). Successive
> function call invocations bind arguments until enough arguments are
> bound to invoke the wrapped function. With it you can do the following:
>
> curryable<std::plus<int> > p;
> auto curried = p(1);
> int i = curried(2);
> assert(i == 3);
>
> Is there any interest in such a thing?

If I can correct the curryable.h code I believe the use of

#elif BOOST_PP_ITERATION_FLAGS() == 1

and

#elif BOOST_PP_ITERATION_FLAGS() == 2

is wrong because BOOST_PP_ITERATION_FLAGS() is always evaluated in these
lines even when BOOST_PP_IS_ITERATING is not defined. I think instead
you must specify:

#else
#if BOOST_PP_ITERATION_FLAGS() == 1
....
#else
#if BOOST_PP_ITERATION_FLAGS() == 2
....
#endif
#endif

instead. Although this change still produces compiler errors with gcc
and Boost 1.47 and below ( Paul Mensonsides is looking into that since
he knows how iteration works with Boost PP ), it solves the problem
compiling with gcc and the latest Boost PP on the trunk.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk