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 // <string> 11 12 // unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10); 13 // unsigned long long stoull(const wstring& str, size_t *idx = 0, int base = 10); 14 15 #include <string> 16 #include <cassert> 17 18 int main() 19 { 20 assert(std::stoull("0") == 0); 21 assert(std::stoull(L"0") == 0); 22 assert(std::stoull("-0") == 0); 23 assert(std::stoull(L"-0") == 0); 24 assert(std::stoull(" 10") == 10); 25 assert(std::stoull(L" 10") == 10); 26 size_t idx = 0; 27 assert(std::stoull("10g", &idx, 16) == 16); 28 assert(idx == 2); 29 idx = 0; 30 assert(std::stoull(L"10g", &idx, 16) == 16); 31 assert(idx == 2); 32 idx = 0; 33 try 34 { 35 std::stoull("", &idx); 36 assert(false); 37 } 38 catch (const std::invalid_argument&) 39 { 40 assert(idx == 0); 41 } 42 idx = 0; 43 try 44 { 45 std::stoull(L"", &idx); 46 assert(false); 47 } 48 catch (const std::invalid_argument&) 49 { 50 assert(idx == 0); 51 } 52 try 53 { 54 std::stoull(" - 8", &idx); 55 assert(false); 56 } 57 catch (const std::invalid_argument&) 58 { 59 assert(idx == 0); 60 } 61 try 62 { 63 std::stoull(L" - 8", &idx); 64 assert(false); 65 } 66 catch (const std::invalid_argument&) 67 { 68 assert(idx == 0); 69 } 70 try 71 { 72 std::stoull("a1", &idx); 73 assert(false); 74 } 75 catch (const std::invalid_argument&) 76 { 77 assert(idx == 0); 78 } 79 try 80 { 81 std::stoull(L"a1", &idx); 82 assert(false); 83 } 84 catch (const std::invalid_argument&) 85 { 86 assert(idx == 0); 87 } 88 } 89