Created
January 8, 2016 21:58
-
-
Save Luiz-Monad/ee6017d9617045cf98c4 to your computer and use it in GitHub Desktop.
Peano numbers with constexpr metaprogramming (yet another implementation)
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
template<typename T> | |
struct S { | |
typedef T Previous; | |
enum { ToInt = T::ToInt + 1 }; | |
}; | |
struct Z { enum { ToInt = 0 }; }; | |
template<typename T> | |
struct ToType { | |
typedef T TypeValue; | |
}; | |
template<> | |
struct ToType<Z> { | |
typedef Z TypeValue; | |
}; | |
template<typename T> | |
struct ToType<S<T>> { | |
typedef S<typename ToType<T>::TypeValue> TypeValue; | |
}; | |
#define P(n) n::Previous | |
#define TO_INT(n) n::ToInt | |
int k = TO_INT(P( S < S < Z > > )); | |
int main(int argc, char** argv) { | |
int i = k; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment