
Boost : 
From: joel de guzman (djowel_at_[hidden])
Date: 20020321 21:37:15
Hi,
How about this code:
struct square_ {
template <typename ArgX>
struct result { typedef ArgX type; };
template <typename ArgX>
ArgX operator()(ArgX arg1) {
return arg1 * arg1;
}
};
function<square_> square;
int
main()
{
std::cout << "Square of " << 5 << " is " << square(5)() << std::endl;
std::cout << "Double Square of " << 5 << " is " << square(square(5))() << std::endl;
}
will print out:
Square of 5 is 25
Double Square of 5 is 625
Am I missing something? If so, pardon my for being slow.
Cheers,
Joel
 Original Message 
From: "Joel Young" :
>
> So phoenix looks really cool!
>
> I was playing around with Phoenix trying to get the following:
>
>  \ \
> double  /\ f . /\ x. f(f x)
>  / \ / \
>
>
> but the best I was able to figure out is:
>
>
>  \
> double  /\ (f, x).f(f x)
>  / \
>
>
> where double = fof in below code snippet:
>
> Any suggestions?
>
> // cut
> struct fof_ {
> template <typename ArgF, typename ArgX>
> struct result { typedef ArgX type; };
>
> template <typename ArgF, typename ArgX>
> ArgX operator()(ArgF arg1, ArgX arg2) {
> return arg1(arg1(arg2))();
> }
> };
>
> // fof equiv lambda(f,x).f(f x)
> function<fof_> fof;
>
> struct square_ {
> template <typename ArgX>
> struct result { typedef ArgX type; };
>
> template <typename ArgX>
> ArgX operator()(ArgX arg1) {
> return arg1 * arg1;
> }
> };
>
> function<square_> square;
>
> int
> main()
> {
> std::cout << "Square of " << 5 << " is " << square(5)() << std::endl;
> std::cout << "Double Square of " << 5 << " is " << fof(square,5)() << std::endl;
> }
> // cut
>
>
> Joel
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk