Skip to content

Instantly share code, notes, and snippets.

@BillyDonahue
Created November 13, 2019 17:35
Show Gist options
  • Save BillyDonahue/2abb8f1dc495e14cd6bf869304b58578 to your computer and use it in GitHub Desktop.
Save BillyDonahue/2abb8f1dc495e14cd6bf869304b58578 to your computer and use it in GitHub Desktop.
#include <cstdint>
#include <iostream>
#include <type_traits>
template <typename> const std::string tName{"???"};
template <> const std::string tName<char>{"char"};
template <> const std::string tName<signed char>{"signed char"};
template <> const std::string tName<unsigned char>{"unsigned char"};
template <> const std::string tName<short>{"short"};
template <> const std::string tName<unsigned short>{"unsigned short"};
template <> const std::string tName<int>{"int"};
template <> const std::string tName<unsigned int>{"unsigned int"};
template <> const std::string tName<long>{"long"};
template <> const std::string tName<unsigned long>{"unsigned long"};
template <> const std::string tName<long long>{"long long"};
template <> const std::string tName<unsigned long long>{"unsigned long long"};
int main() {
#define PR(t) std::cout << #t " is " << tName<t> << std::endl;
PR(int8_t);
PR(uint8_t);
PR(int16_t);
PR(int32_t);
PR(int64_t);
PR(size_t);
PR(ptrdiff_t);
PR(intptr_t);
PR(uintptr_t);
return 0;
}
@BillyDonahue
Copy link
Author

OSX: make CXXFLAGS=-std=c++17 types_test ; ./types_test

int8_t is signed char
uint8_t is unsigned char
int16_t is short
int32_t is int
int64_t is long long
size_t is unsigned long
ptrdiff_t is long
intptr_t is long
uintptr_t is unsigned long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment