c_cpp 带有C ++模板的Peano数字
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 带有C ++模板的Peano数字相关的知识,希望对你有一定的参考价值。
#include "stdafx.h"
class z { };
template<typename>
class s { };
template<typename, typename>
class add { };
template<typename n>
struct add<z, n>
{
typedef n type;
};
template<typename m, typename n>
struct add<s<m>, n>
{
typedef typename add<m, s<n>>::type type;
};
template<typename>
struct eval { };
template<>
struct eval<z>
{
static const int value = 0;
};
template<typename n>
struct eval<s<n>>
{
static const int value = 1 + eval<n>::value;
};
int main()
{
printf("%d\n", eval<add<s<s<z>>, s<s<s<z>>>>::type>::value);
}
以上是关于c_cpp 带有C ++模板的Peano数字的主要内容,如果未能解决你的问题,请参考以下文章