[RISCV] Add shrinkwrap test cases showing gaps in current impl
[llvm-project.git] / libcxx / test / support / parse_integer.h
blob36f8f7b79881b831be817d64b1acfbc1d975ccf1
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LIBCPP_TEST_SUPPORT_PARSE_INTEGER_H
10 #define LIBCPP_TEST_SUPPORT_PARSE_INTEGER_H
12 #include <string>
14 namespace detail {
15 template <class T>
16 struct parse_integer_impl;
18 template <>
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);
26 template <>
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);
34 template <>
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);
42 template <>
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);
50 template <>
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);
58 template <>
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 } // 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