|
![](/i/fill.gif) |
Orchid Win7 v1 <voi### [at] dev null> wrote:
> Listing #1:
> Type1 x = foo();
> Type2 y = bar(x);
> Type3 z = baz(y);
> return z;
Btw, I don't know if this is exactly what you are looking for, but I think
it achieves at least close to what you are attempting:
auto x = [](int i) { return i*2; };
auto y = [x](int i) { return x(i*3); };
auto z = [y](int i) { return y(i*5); };
std::cout << z(3) << std::endl;
(Capturing the other functions by value is far easier than taking them
as function parameters because this way you don't have to care about the
type of the anonymous function. Unfortunately lambda functions cannot yet
be templated, which is a bummer.)
If you wanted to return that 'z' from a function, it's slightly less
intuitive (because function return values cannot be 'auto'). You have
to do it like this:
//--------------------------------------------------------------------
#include <iostream>
#include <functional>
std::function<int(int)> gimmeTheFunction()
{
auto x = [](int i) { return i*2; };
auto y = [x](int i) { return x(i*3); };
auto z = [y](int i) { return y(i*5); };
return z;
}
int main()
{
auto func = gimmeTheFunction();
std::cout << func(3) << std::endl;
}
//--------------------------------------------------------------------
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |