1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // int stoi(const string& str, size_t *idx = 0, int base = 10);
13 // int stoi(const wstring& str, size_t *idx = 0, int base = 10);
20 assert(std::stoi("0") == 0);
21 assert(std::stoi(L
"0") == 0);
22 assert(std::stoi("-0") == 0);
23 assert(std::stoi(L
"-0") == 0);
24 assert(std::stoi("-10") == -10);
25 assert(std::stoi(L
"-10") == -10);
26 assert(std::stoi(" 10") == 10);
27 assert(std::stoi(L
" 10") == 10);
29 assert(std::stoi("10g", &idx
, 16) == 16);
32 assert(std::stoi(L
"10g", &idx
, 16) == 16);
34 if (std::numeric_limits
<long>::max() > std::numeric_limits
<int>::max())
38 std::stoi("0x100000000", &idx
, 16);
41 catch (const std::out_of_range
&)
46 std::stoi(L
"0x100000000", &idx
, 16);
49 catch (const std::out_of_range
&)
59 catch (const std::invalid_argument
&)
68 catch (const std::invalid_argument
&)
74 std::stoi(" - 8", &idx
);
77 catch (const std::invalid_argument
&)
83 std::stoi(L
" - 8", &idx
);
86 catch (const std::invalid_argument
&)
92 std::stoi("a1", &idx
);
95 catch (const std::invalid_argument
&)
101 std::stoi(L
"a1", &idx
);
104 catch (const std::invalid_argument
&)