かなりマニュアルと起こってほとんどの魔法が、あなたはchar
からsigned
/unsigned
を削除したい場合は、このテンプレートを使用することができます。
template <typename T>
struct remove_sign_from_char {
typedef T type;
};
template <>
struct remove_sign_from_char<signed char>
{
typedef char type;
};
template <>
struct remove_sign_from_char<unsigned char>
{
typedef char type;
};
int main() {
static_assert(std::is_same< char, remove_sign_from_char<unsigned char>::type >::value);
static_assert(std::is_same< char, remove_sign_from_char<signed char>::type >::value);
static_assert(std::is_same< char, remove_sign_from_char<char>::type >::value);
static_assert(std::is_same< int, remove_sign_from_char<int>::type >::value);
}
なぜこのようなものが必要でしょうか?いくつかの数学的計算を行っているならば、http://www.cplusplus.com/reference/std/limits/numeric_limits/を使用してください。 –