In C++ type traits std::is_integral<T>::value
returns true even if T is bool which is correct as per its description.
But if bool is a different type than other integral types, why its considered as integral type in this case? why we don't have a separate std::is_boolean type trait?
#include <iostream>
#include <type_traits>
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_same<int, bool>::value << ' '; // ~ false
std::cout << std::is_same<unsigned int, bool>::value << ' '; // ~ false
std::cout << '\n';
std::cout << std::is_integral<bool>::value << ' '; // ~ true
return 0;
}
Aucun commentaire:
Enregistrer un commentaire