Created
April 27, 2018 13:30
-
-
Save mirekfranc/a1fe0ca9e0d0fd2a2bac73ac9f715e85 to your computer and use it in GitHub Desktop.
char != signed char && char != unsigned char
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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