Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- namespace details {
- template<std::size_t Value>
- using constant = std::integral_constant<std::size_t, Value>;
- template<std::size_t>
- struct fibonacci_number;
- template<>
- struct fibonacci_number<0> : constant<0> { };
- template<>
- struct fibonacci_number<1> : constant<1> { };
- template<>
- struct fibonacci_number<2> : constant<1> { };
- template<std::size_t N>
- struct fibonacci_number {
- using _1 = typename fibonacci_number<N - 1>::type;
- using _2 = typename fibonacci_number<N - 2>::type;
- using type = constant<_1{} + _2{}>;
- };
- }
- template<std::size_t N>
- struct fibonacci_number : details::fibonacci_number<N>::type { };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement