|
![](/i/fill.gif) |
Am 22.04.2012 17:56, schrieb Orchid Win7 v1:
> On 22/04/2012 01:43 PM, Warp wrote:
>> Orchid Win7 v1<voi### [at] dev null> wrote:
>>> 1. You can take a 5-argument function, pass it 2 argument, and get a
>>> 3-argument function as the result.
>>
>> Would this be currying in C++?
>>
>> std::function<int(int)> multiplierFunction(int multiplier)
>> {
>> return [multiplier](int value) { return value * multiplier; };
>> }
>>
>> The above function returns a function that takes an integral as parameter
>> and returns it multiplied by the specified multiplier.
>
> Yeah, I think that would satisfy my idea of "curried function".
>
> The question is, does
>
> multiplierFunction(3)(4)
>
> or similar yield a 12?
Sure, why not? multiplierFunction(3) returns a valid function, so
invoking its () operator calls the function with the respective
parameter(s).
(You could achieve the same syntax by having multiplierFunction() return
an object with an overridden () operator rather than a function, but of
course that would be cheating.)
Post a reply to this message
|
![](/i/fill.gif) |