|
| 1 | +// fig15_06.cpp |
| 2 | +// Using type traits to test whether types are |
| 3 | +// integral types, floating-point types or arithmetic types. |
| 4 | +#include <fmt/format.h> |
| 5 | +#include <iostream> |
| 6 | +#include <string> |
| 7 | +#include <type_traits> |
| 8 | + |
| 9 | +int main() { |
| 10 | + std::cout << fmt::format("{}\n{}{}\n{}{}\n{}{}\n{}{}\n{}{}\n\n", |
| 11 | + "CHECK WITH TYPE TRAITS WHETHER TYPES ARE INTEGRAL", |
| 12 | + "std::is_integral<int>::value: ", std::is_integral<int>::value, |
| 13 | + "std::is_integral_v<int>: ", std::is_integral_v<int>, |
| 14 | + "std::is_integral_v<long>: ", std::is_integral_v<long>, |
| 15 | + "std::is_integral_v<float>: ", std::is_integral_v<float>, |
| 16 | + "std::is_integral_v<std::string>: ", |
| 17 | + std::is_integral_v<std::string>); |
| 18 | + |
| 19 | + std::cout << fmt::format("{}\n{}{}\n{}{}\n{}{}\n{}{}\n{}{}\n\n", |
| 20 | + "CHECK WITH TYPE TRAITS WHETHER TYPES ARE FLOATING POINT", |
| 21 | + "std::is_floating_point<float>::value: ", |
| 22 | + std::is_floating_point<float>::value, |
| 23 | + "std::is_floating_point_v<float>: ", |
| 24 | + std::is_floating_point_v<float>, |
| 25 | + "std::is_floating_point_v<double>: ", |
| 26 | + std::is_floating_point_v<double>, |
| 27 | + "std::is_floating_point_v<int>: ", |
| 28 | + std::is_floating_point_v<int>, |
| 29 | + "std::is_floating_point_v<std::string>: ", |
| 30 | + std::is_floating_point_v<std::string>); |
| 31 | + |
| 32 | + std::cout << fmt::format("{}\n{}{}\n{}{}\n{}{}\n{}{}\n", |
| 33 | + "CHECK WITH TYPE TRAITS WHETHER TYPES CAN BE USED IN ARITHMETIC", |
| 34 | + "std::is_arithmetic<int>::value: ", std::is_arithmetic<int>::value, |
| 35 | + "std::is_arithmetic_v<int>: ", std::is_arithmetic_v<int>, |
| 36 | + "std::is_arithmetic_v<double>: ", std::is_arithmetic_v<double>, |
| 37 | + "std::is_arithmetic_v<std::string>: ", |
| 38 | + std::is_arithmetic_v<std::string>); |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +/************************************************************************** |
| 43 | + * (C) Copyright 1992-2020 by Deitel & Associates, Inc. and * |
| 44 | + * Pearson Education, Inc. All Rights Reserved. * |
| 45 | + * * |
| 46 | + * DISCLAIMER: The authors and publisher of this book have used their * |
| 47 | + * best efforts in preparing the book. These efforts include the * |
| 48 | + * development, research, and testing of the theories and programs * |
| 49 | + * to determine their effectiveness. The authors and publisher make * |
| 50 | + * no warranty of any kind, expressed or implied, with regard to these * |
| 51 | + * programs or to the documentation contained in these books. The authors * |
| 52 | + * and publisher shall not be liable in any event for incidental or * |
| 53 | + * consequential damages in connection with, or arising out of, the * |
| 54 | + * furnishing, performance, or use of these programs. * |
| 55 | + **************************************************************************/ |
0 commit comments