I have this struct template
template<typename N>
struct Succ{};
and this function template
template<typename N> N dec(Succ<N> s_n){
N n;
return n;
}
and this does exactly what I want, if I decrement once too often, I get a compiler error.
Now, I would like to use this style of code in my projects for catching errors, however it is very tedious to create initial "values", I mean, 2 is already Succ<Succ<SomeType>>
.
How can I accomplish this with C++ templates? Something like
Nat<2,SomeType> two;
which is the same as
Succ<Succ<SomeType>> two;
And can some people give me links or other resources to this kind of template programming please? Like, how to implement Peano Arithmetic with C++ templates and how to create Type Numbers more easily.