folks. I have a situation like, template argument depends in running time. My function:
string DecToBin(int num)
{
bitset<(num < 256 ? 8 : 32)> bits(num);
return bits.to_string();
}
So, it cannot be compile for sure. What a solution can be except example below? Thanks
string DecToBin(int num)
{
if(num < pow(2, 8))
{
bitset<8> bits(num);
return bits.to_string();
} else if(num < pow(2, 16))
{
bitset<16> bits(num);
return bits.to_string();
} else if(num < pow(2, 32))
{
bitset<32> bits(num);
return bits.to_string();
} else
{
bitset<64> bits(num);
return bits.to_string();
}
}