Last active
December 17, 2016 03:17
-
-
Save yshui/61ec77b3fa6ea2d5855ac8165cf2c055 to your computer and use it in GitHub Desktop.
Symbol name goes BOOM!
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 First, typename ...Rest> | |
struct Int{ | |
using Next = Int<Int<First, Rest...>, First, Rest...>; | |
using Prev = First; | |
}; | |
struct Zero{ | |
using Next = Int<Zero, Int<Zero>>; | |
}; | |
template<typename A, typename B> | |
struct Plus{ | |
using Result=typename Plus<A,typename B::Prev>::Result::Next; | |
}; | |
template<typename A> | |
struct Plus<A, Zero>{ | |
using Result=A; | |
}; | |
template<typename A> | |
struct Double { | |
using Result=typename Plus<A,A>::Result; | |
}; | |
template<typename L, typename R> | |
struct Bottom { | |
}; | |
template<typename Level, typename L, typename R> | |
struct Boom { | |
using Inner = Boom<typename Level::Prev, typename Boom<typename Level::Prev,L,typename Level::Prev>::Inner, typename Boom<typename Level::Prev,R,typename Level::Prev>::Inner>; | |
}; | |
template<typename L, typename R> | |
struct Boom<Zero,L,R> { | |
using Inner = Bottom<L,R>; | |
}; | |
template<typename A> | |
struct PowerOf2 { | |
using Result = typename Double<typename PowerOf2<typename A::Prev>::Result>::Result; | |
}; | |
template<> | |
struct PowerOf2<Zero> { | |
using Result = Zero::Next; | |
}; | |
using One=Zero::Next; | |
using Two=Double<One>::Result; | |
using Four=Double<Two>::Result; | |
using Eight=Double<Four>::Result; | |
using Sixteen=Double<Eight>::Result; | |
using I256 = PowerOf2<Eight>::Result; | |
template<typename T> | |
int x() {return 0;} | |
int main(){ | |
return x<typename Boom<I256,Zero,One>::Inner>(); | |
} | |
// Below is results when using Boom<Eight, Zero, One>, for Boom<I256, Zero, One> you can try yourself | |
// g++ boom.cpp | |
// objdump -t a.out | |
// ... | |
// 00000000004004d1 w F .text 000000000000000b _Z1xI4BoomI3IntIS1_IS1_IS1_IS1_IS1_IS1_IS1_IS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