- #include \"prelude.h\"
- using namespace fcpp;
- #include <iostream>
- using namespace std;
- bool divisible( int x, int y ) { return x%y==0; }
- struct Factors : public CFunType<int,OddList<int> > {
- OddList<int> operator()( int x ) const {
- return filter( curry2(ptr_to_fun(&divisible),x), enumFromTo(1,x) );
- }
- } factors;
- int main()
- {
- OddList<int> odd = factors(20);
- while (odd) {
- cout << head(odd) << endl;
- odd = tail(odd);
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/13112012301.html
来源: http://www.codesnippet.cn/detail/13112012301.html