if:
template<typename T>
std::string build_data_from(T val)
{
std::string result;
for (size_t i = 0; i < sizeof(val); i++)
{
result.insert(0, 1, char(val));
if (sizeof (T) > 1)
val = val >> 8;
}
return result;
}
if (sizeof(T) > 1) T, , . , T char, , .
Btw: you should declare your variable ias size_t, rather than int. the result sizeof()is equal size_t, and some compilers (e.g. gcc) warn you if you are doing a comparison between unsigned integers.
source
share