1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LIBCPP_TEST_SUPPORT_PARSE_INTEGER_H
10 #define LIBCPP_TEST_SUPPORT_PARSE_INTEGER_H
16 struct parse_integer_impl
;
19 struct parse_integer_impl
<int> {
20 template <class CharT
>
21 int operator()(std::basic_string
<CharT
> const& str
) const {
22 return std::stoi(str
);
27 struct parse_integer_impl
<long> {
28 template <class CharT
>
29 long operator()(std::basic_string
<CharT
> const& str
) const {
30 return std::stol(str
);
35 struct parse_integer_impl
<long long> {
36 template <class CharT
>
37 long long operator()(std::basic_string
<CharT
> const& str
) const {
38 return std::stoll(str
);
43 struct parse_integer_impl
<unsigned int> {
44 template <class CharT
>
45 unsigned int operator()(std::basic_string
<CharT
> const& str
) const {
46 return std::stoul(str
);
51 struct parse_integer_impl
<unsigned long> {
52 template <class CharT
>
53 unsigned long operator()(std::basic_string
<CharT
> const& str
) const {
54 return std::stoul(str
);
59 struct parse_integer_impl
<unsigned long long> {
60 template <class CharT
>
61 unsigned long long operator()(std::basic_string
<CharT
> const& str
) const {
62 return std::stoull(str
);
65 } // end namespace detail
67 template <class T
, class CharT
>
68 T
parse_integer(std::basic_string
<CharT
> const& str
) {
69 return detail::parse_integer_impl
<T
>()(str
);
72 #endif // LIBCPP_TEST_SUPPORT_PARSE_INTEGER_H