C++ 用Boost.Bind表示教会数字

C++ 用Boost.Bind表示教会数字,c++,boost,boost-bind,lambda-calculus,church-encoding,C++,Boost,Boost Bind,Lambda Calculus,Church Encoding,教堂数字可以用C++0x(C++11?)表示,使用语言的新lambda部分,例如: typedef函数F; 静态常量F id=[=](int x){return x;}; 函数集(无符号整数i) { 如果(i==0){ return[=](F){return id;}; } 返回[=](F){ F tmp=[=](int x){return F(church(i-1)(F)(x));}; 返回tmp; }; } 是否可以使用Boost.Bind和C++03来表示教堂数字?如果是,怎么做?好的,

教堂数字可以用C++0x(C++11?)表示,使用语言的新lambda部分,例如:

typedef函数F;
静态常量F id=[=](int x){return x;};
函数集(无符号整数i)
{
如果(i==0){
return[=](F){return id;};
}
返回[=](F){
F tmp=[=](int x){return F(church(i-1)(F)(x));};
返回tmp;
};
}

是否可以使用Boost.Bind和C++03来表示教堂数字?如果是,怎么做?

好的,我对教堂数字一无所知,而且我还没有实际测试过这段代码,但类似的东西应该可以工作:)

//转发
boost::函数church(unsigned int i);
typedef boost::函数F;
int idFunc(int x)
{
返回x;
}
静态常量F id=boost::bind(&idFunc,_1);
F.0(F)
{
返回id;
}
int(F,int i,int x)
{
报税表f(教会(i-1)(f)(x));
}
F丘奇函数(F,int i)
{
返回boost::绑定(内部,f,i,_1);
}
boost::函数church(无符号整数i)
{
如果(i==0)
{
返回boost::绑定(&0,_1);
}
返回boost::bind(&ChurchFunc,_1,i);
}

好的,我对教堂数字一无所知,而且我还没有实际测试过这段代码,但类似的东西应该可以工作:)

//转发
boost::函数church(unsigned int i);
typedef boost::函数F;
int idFunc(int x)
{
返回x;
}
静态常量F id=boost::bind(&idFunc,_1);
F.0(F)
{
返回id;
}
int(F,int i,int x)
{
报税表f(教会(i-1)(f)(x));
}
F丘奇函数(F,int i)
{
返回boost::绑定(内部,f,i,_1);
}
boost::函数church(无符号整数i)
{
如果(i==0)
{
返回boost::绑定(&0,_1);
}
返回boost::bind(&ChurchFunc,_1,i);
}
typedef function<int(int)> F;
static const F id = [=](int x) { return x; };

function<F(F)> church(unsigned int i)
{
  if(i == 0) {
    return [=] (F f) { return id; };
  }

  return [=] (F f) {
    F tmp = [=](int x) { return f(church(i-1)(f)(x)); };
    return tmp;
  };
}
// forward
boost::function<F (F)> church(unsigned int i);

typedef boost::function<int (int)> F;

int idFunc(int x)
{
  return x;
}

static const F id = boost::bind(&idFunc, _1);

F ChurchFunc0(F f)
{
  return id;
}

int ChurchFuncInner(F f, int i, int x)
{
  return f(church(i - 1)(f)(x));
}

F ChurchFunc(F f, int i)
{
  return boost::bind(&ChurchFuncInner, f, i, _1);
}

boost::function<F (F)> church(unsigned int i)
{
  if (i == 0)
  {
    return boost::bind(&ChurchFunc0, _1);
  }

  return boost::bind(&ChurchFunc, _1, i);
}