Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 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 | } |
Marshall Clow | 914993d | 2013-08-13 15:52:51 +0000 | [diff] [blame^] | 88 | // LWG issue #2009 |
| 89 | try |
| 90 | { |
| 91 | std::stoull("9999999999999999999999999999999999999999999999999", &idx); |
| 92 | assert(false); |
| 93 | } |
| 94 | catch (const std::out_of_range&) |
| 95 | { |
| 96 | assert(idx == 0); |
| 97 | } |
| 98 | try |
| 99 | { |
| 100 | std::stoull(L"9999999999999999999999999999999999999999999999999", &idx); |
| 101 | assert(false); |
| 102 | } |
| 103 | catch (const std::out_of_range&) |
| 104 | { |
| 105 | assert(idx == 0); |
| 106 | } |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 107 | } |