integral.pass.cpp (2321B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11 11 12 // XFAIL: with_system_cxx_lib=macosx10.14 13 // XFAIL: with_system_cxx_lib=macosx10.13 14 // XFAIL: with_system_cxx_lib=macosx10.12 15 // XFAIL: with_system_cxx_lib=macosx10.11 16 // XFAIL: with_system_cxx_lib=macosx10.10 17 // XFAIL: with_system_cxx_lib=macosx10.9 18 // XFAIL: with_system_cxx_lib=macosx10.8 19 // XFAIL: with_system_cxx_lib=macosx10.7 20 21 // <charconv> 22 23 // to_chars_result to_chars(char* first, char* last, Integral value, 24 // int base = 10) 25 26 #include "charconv_test_helpers.h" 27 28 template <typename T> 29 struct test_basics : to_chars_test_base<T> 30 { 31 using to_chars_test_base<T>::test; 32 using to_chars_test_base<T>::test_value; 33 34 void operator()() 35 { 36 test(0, "0"); 37 test(42, "42"); 38 test(32768, "32768"); 39 test(0, "0", 10); 40 test(42, "42", 10); 41 test(32768, "32768", 10); 42 test(0xf, "f", 16); 43 test(0xdeadbeaf, "deadbeaf", 16); 44 test(0755, "755", 8); 45 46 for (int b = 2; b < 37; ++b) 47 { 48 using xl = std::numeric_limits<T>; 49 50 test_value(1, b); 51 test_value(xl::lowest(), b); 52 test_value((xl::max)(), b); 53 test_value((xl::max)() / 2, b); 54 } 55 } 56 }; 57 58 template <typename T> 59 struct test_signed : to_chars_test_base<T> 60 { 61 using to_chars_test_base<T>::test; 62 using to_chars_test_base<T>::test_value; 63 64 void operator()() 65 { 66 test(-1, "-1"); 67 test(-12, "-12"); 68 test(-1, "-1", 10); 69 test(-12, "-12", 10); 70 test(-21734634, "-21734634", 10); 71 test(-2647, "-101001010111", 2); 72 test(-0xcc1, "-cc1", 16); 73 74 for (int b = 2; b < 37; ++b) 75 { 76 using xl = std::numeric_limits<T>; 77 78 test_value(0, b); 79 test_value(xl::lowest(), b); 80 test_value((xl::max)(), b); 81 } 82 } 83 }; 84 85 int main() 86 { 87 run<test_basics>(integrals); 88 run<test_signed>(all_signed); 89 }