|
Boost : |
From: Joel de Guzman (djowel_at_[hidden])
Date: 2003-01-24 22:11:35
----- Original Message -----
From: "Joel de Guzman" <djowel_at_[hidden]>
> A good start is libs/phoenix/test/functors_tests.cpp
> and libs/phoenix/example/fundamental/sample3.cpp
> There are jamfiles in there FWIW.
BTW, here's the lambda-lambda solution posed by Joel Young:
#include <iostream>
#include "boost/phoenix/operators.hpp"
#include "boost/phoenix/primitives.hpp"
#include "boost/phoenix/composite.hpp"
#include "boost/phoenix/functions.hpp"
//////////////////////////////////
using namespace std;
using namespace phoenix;
//////////////////////////////////
struct square_ {
template <typename X>
struct result { typedef X type; };
template <typename X>
X operator()(X x)
{
return x * x;
}
};
function<square_> square;
//////////////////////////////////
template <typename F>
struct ffx {
template <typename X>
struct result { typedef X type; };
ffx(F f_) : f(f_) {}
template <typename X>
X operator()(X x)
{
return f(f(x));
}
F f;
};
template <typename F>
function<ffx<F> >
doub(function<F> f)
{
return function<ffx<F> >(f.op);
}
//////////////////////////////////
int
main()
{
cout << doub(square)(5.0)() << endl;
cout << doub(doub(square))(5.0)() << endl;
cout << doub(doub(doub(square)))(5.0)() << endl;
return 0;
}
Cheers,
Joel de Guzman
joel_at_[hidden]
http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk