Skip to content

Instantly share code, notes, and snippets.

@marc0x71
Last active October 15, 2024 07:40
Show Gist options
  • Save marc0x71/e4638f81b4b5c863b562f10e24a8a18a to your computer and use it in GitHub Desktop.
Save marc0x71/e4638f81b4b5c863b562f10e24a8a18a to your computer and use it in GitHub Desktop.
Mostra dimensione, min e max per ogni tipo base C++
#include <iostream>
#include <limits>
#include <string_view>
#include <type_traits>
template <typename T> void print_details(std::string_view type) {
std::cout << type << " | " << 8 * sizeof(T) << " | ";
if constexpr (std::is_same_v<T, char> || std::is_same_v<T, unsigned char>) {
std::cout << static_cast<int>(std::numeric_limits<T>::min()) << " | "
<< static_cast<int>(std::numeric_limits<T>::max()) << " |\n";
} else {
std::cout << std::numeric_limits<T>::min() << " | "
<< std::numeric_limits<T>::max() << " |\n";
}
}
int main() {
print_details<bool>("bool");
print_details<char>("signed char");
print_details<unsigned char>("unsigned char");
print_details<short>("short");
print_details<unsigned short>("unsigned short");
print_details<int>("int");
print_details<unsigned>("unsigned");
print_details<long>("long");
print_details<unsigned long>("unsigned long");
print_details<float>("float");
print_details<double>("double");
print_details<long double>("long double");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment