Pergunta de entrevista da empresa Bloomberg

C++ template metaprogramming (that team was into functional programming and compile time computations). Standard, find nth Fibonacci number using recursive templates.

Respostas da entrevista

Sigiloso

30 de out. de 2014

The obvious simple solution: #include template struct FIB { enum { RESULT = FIB::RESULT + FIB::RESULT }; }; template struct FIB { enum { RESULT = 0 }; }; template struct FIB { enum { RESULT = 1 }; }; int main() { std::cout ::RESULT << std::endl; return EXIT_SUCCESS; }

Sigiloso

15 de abr. de 2019

template struct fibonacci { using type = unsigned long int; static constexpr type value = fibonacci::value + fibonacci::value; }; template struct fibonacci { using type = unsigned long int; static constexpr type value = 0; }; template struct fibonacci { using type = unsigned long int; static constexpr type value = 1; }; int main() { return fibonacci::value; }