S
Siemel Naran
Hi. Is there a way to convert the type signed int to the type unsigned int,
char to unsigned char, signed char to unsigned char, and so on for all the
fundamental integer types? Something like
template <>
struct to_unsigned<signed int> : public std::unary_function<signed int,
unsigned int>
{
unsigned int operator()(signed int x) const { return x; }
};
template <>
struct to_unsigned<unsigned int> : public std::unary_function<unsigned int,
unsigned int>
{
unsigned int operator()(unsigned int x) const { return x; }
};
template <>
struct to_unsigned<char> : public std::unary_function<char, unsigned char>
{
unsigned char operator()(char x) const { return x; }
};
template <>
struct to_unsigned<signed char> : public std::unary_function<signed char,
unsigned char>
{
unsigned char operator()(signed char x) const { return x; }
};
template <>
struct to_unsigned<unsigned char> : public std::unary_function<unsigned
char, unsigned char>
{
unsigned char operator()(unsigned char x) const { return x; }
};
But I'd like to cover all the fundamental integer types (where do they end:
at long or long long or long long long). Also, is there a way to do it that
involves less typing? Also, I want tounsigned<double> to not have a typedef
result defined.
Thanks.
char to unsigned char, signed char to unsigned char, and so on for all the
fundamental integer types? Something like
template <>
struct to_unsigned<signed int> : public std::unary_function<signed int,
unsigned int>
{
unsigned int operator()(signed int x) const { return x; }
};
template <>
struct to_unsigned<unsigned int> : public std::unary_function<unsigned int,
unsigned int>
{
unsigned int operator()(unsigned int x) const { return x; }
};
template <>
struct to_unsigned<char> : public std::unary_function<char, unsigned char>
{
unsigned char operator()(char x) const { return x; }
};
template <>
struct to_unsigned<signed char> : public std::unary_function<signed char,
unsigned char>
{
unsigned char operator()(signed char x) const { return x; }
};
template <>
struct to_unsigned<unsigned char> : public std::unary_function<unsigned
char, unsigned char>
{
unsigned char operator()(unsigned char x) const { return x; }
};
But I'd like to cover all the fundamental integer types (where do they end:
at long or long long or long long long). Also, is there a way to do it that
involves less typing? Also, I want tounsigned<double> to not have a typedef
result defined.
Thanks.