What will be printed out as a result of the following code execution?
#include <iostream>
#include <string>

template<int T>
std::string StrangeFunc()
{
    return StrangeFuncStruct<T>::value();
}

template<int T, bool lt16 = (T<16)>
struct StrangeFuncStruct
{
    static std::string value()
    {
        return StrangeFuncStruct<T, (T<16)>::value();
    }
};

template<int T>
struct StrangeFuncStruct<T, true>
{
    static std::string value()
    {
        return std::string(1, T + ((T>9)?'A'-10:'0'));
    }
};

template<int T>
struct StrangeFuncStruct<T, false>
{
    static std::string value()
    {
        return StrangeFuncStruct<(T/16)>::value()
             + StrangeFuncStruct<(T%16)>::value();
    }
};

int main()
{
    std::cout << StrangeFunc<137+137*256>() << std::endl;
}
Explanation
This is a template implementation of the algorithm for converting an integer constant into a string with a hexadecimal representation of a number.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты