Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
char != signed char && char != unsigned char
// x86_64-redhat-linux
#include <iostream>
template<typename T> struct foo;
#ifndef NO_CHAR
template<> struct foo<char> { void operator()() { std::cout << "char" << std::endl;} };
#endif
template<> struct foo<unsigned char> { void operator()() { std::cout << "unsigned char" << std::endl;} };
template<> struct foo<signed char> { void operator()() { std::cout << "signed char" << std::endl;} };
template<> struct foo<unsigned int> { void operator()() { std::cout << "unsigned ing" << std::endl;} };
template<> struct foo<signed int> { void operator()() { std::cout << "signed int" << std::endl;} };
int main()
{
foo<char>()(); // char or compiletime error if -DNO_CHAR
foo<unsigned char>()(); // unsigned char
foo<signed char>()(); // signed char
foo<int>()(); // unsigned int
struct { int nothing:1; unsigned int nosign:1; signed int sign:1; } bitfield;
foo<decltype(bitfield.nothing)>()(); // signed int (but could be unsigned AFAIK)
foo<decltype(bitfield.nosign)>()(); // unsigned int
foo<decltype(bitfield.sign)>()(); // signed int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.