Created
October 26, 2021 19:24
-
-
Save Soft/140d8b3bdf1b9cc61c49a36534581774 to your computer and use it in GitHub Desktop.
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
struct Z {}; | |
template <typename N> | |
struct S {}; | |
template <typename A, typename B> | |
struct Add {}; | |
template <typename B> | |
struct Add<Z, B> { | |
using result = B; | |
}; | |
template <typename A,typename B> | |
struct Add<S<A>, B> { | |
using result = typename Add<A, S<B>>::result; | |
}; | |
template <typename A, typename B> | |
struct Mul {}; | |
template <typename B> | |
struct Mul<Z, B> { | |
using result = Z; | |
}; | |
template <typename A, typename B> | |
struct Mul<S<A>, B> { | |
using result = typename Add<B, typename Mul<A, B>::result>::result; | |
}; | |
template <typename A> struct Value {}; | |
template<> struct Value<Z> { | |
static const int value = 0; | |
}; | |
template <typename N> struct Value<S<N>> { | |
static const int value = 1 + Value<N>::value; | |
}; | |
using Two = S<S<Z>>; | |
using Three = S<Two>; | |
using Four = S<Three>; | |
using Five = S<Four>; | |
using Six = S<Five>; | |
using Ten = typename Mul<Five, Two>::result; | |
using Hundred = typename Mul<Ten, Ten>::result; | |
using TwentyFour = typename Add< | |
typename Mul<Four, Five>::result, | |
Four | |
>::result; | |
using Sixty = typename Mul<Ten, Six>::result; | |
using ThreeHundredSixtyFive = typename Add< | |
typename Add< | |
typename Mul<Three, Hundred>::result, | |
Sixty | |
>::result, | |
Five | |
>::result; | |
#include <iostream> | |
int main() { | |
using result = typename Mul< | |
typename Mul< | |
typename Mul<TwentyFour, Sixty>::result, | |
Sixty | |
>::result, | |
ThreeHundredSixtyFive | |
>::result; | |
std::cout << Value<result>::value; | |
return 0; | |
} |
vilhok
commented
Oct 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment