Boost logo

Boost :

From: Joel Young (jdy_at_[hidden])
Date: 2002-03-21 13:41:21


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk