Last active
March 21, 2018 05:21
-
-
Save pnck/d7bd4733f49bd19c2be234da27a8826d to your computer and use it in GitHub Desktop.
peano plus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <functional> | |
struct zero; | |
template <typename V> | |
struct signtype | |
{ | |
using value = typename signtype<V>::value; | |
}; | |
template <> | |
struct signtype<zero> | |
{ | |
using value = zero; | |
}; | |
template <int v> | |
struct num | |
{ | |
using name = signtype<typename num<v-1>::name>; | |
}; | |
template <> | |
struct num<0> | |
{ | |
using name = zero; | |
}; | |
using one = signtype<zero>; | |
using two = signtype<one>; | |
using three = signtype<two>; | |
template <typename V1, typename V2> | |
struct plus; | |
template <typename V2> | |
struct plus<zero,V2> | |
{ | |
using sum = V2; | |
}; | |
template <typename V1, typename V2> | |
struct plus<signtype<V1>,V2> | |
{ | |
using sum = signtype< typename plus<V1,V2>::sum >; | |
}; | |
using result = plus<one,two>::sum; | |
int main() | |
{ | |
printf("Hello World"); | |
printf(" => %d\n",std::is_same<three,num<3>::name>::value); | |
printf(" => %d\n",std::is_same<result,three>::value); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment