Boost logo

Boost :

Subject: Re: [boost] painless currying
From: Larry Evans (cppljevans_at_[hidden])
Date: 2011-09-03 09:28:02

On 08/23/11 14:38, 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?

With the 2 attached files (compiled with gcc4.6 and with boost trunk
[which svn update showed was revision 74198]), the output is:


type_u<0>(type_u const&)
type_u<0>(type_u const&)
type_u<1>(type_u const&)
type_u<0>(type_u const&)
type_u<0>(type_u const&)
type_u<1>(type_u const&)

Compilation finished at Sat Sep 3 08:20:45

which shows several copy CTOR's executed. These copy CTOR
calls were caused by the code like this:

  curryable (Fun f, Arg0 a0, Arg1 a1, Arg2 a2):
  fun (f),
  arg0 (a0),
  arg1 (a1),
  arg2 (a2)

produced by the BOOST_PP code. Is there any way to prevent
these copies, maybe by declarations like:

  Arg0 const&

instead of the existing:




Boost list run by bdawes at, gregod at, cpdaniel at, john at