tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
stoi.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_STRING_STOI_HPP
3#define TETL_STRING_STOI_HPP
4
8
9namespace etl {
10
11namespace detail {
12
13template <etl::integral Int>
14[[nodiscard]] constexpr auto sto_impl(etl::string_view str, etl::size_t* pos, int base) -> Int
15{
16 auto const res = strings::to_integer<Int>(str, static_cast<Int>(base));
17 if (pos != nullptr) {
18 *pos = static_cast<etl::size_t>(etl::distance(str.data(), res.end));
19 }
20 return res.value;
21}
22
23} // namespace detail
24
31[[nodiscard]] constexpr auto stoi(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> int
32{
33 return detail::sto_impl<int>(str, pos, base);
34}
35
42[[nodiscard]] constexpr auto stol(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> long
43{
44 return detail::sto_impl<long>(str, pos, base);
45}
46
53[[nodiscard]] constexpr auto stoll(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> long long
54{
55 return detail::sto_impl<long long>(str, pos, base);
56}
57
64[[nodiscard]] constexpr auto stoul(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> unsigned long
65{
66 return detail::sto_impl<unsigned long>(str, pos, base);
67}
68
75[[nodiscard]] constexpr auto stoull(etl::string_view str, etl::size_t* pos = nullptr, int base = 10)
76 -> unsigned long long
77{
78 return detail::sto_impl<unsigned long long>(str, pos, base);
79}
80
81} // namespace etl
82
83#endif // TETL_STRING_STOI_HPP
constexpr auto distance(It first, It last) -> typename iterator_traits< It >::difference_type
Returns the number of hops from first to last.
Definition distance.hpp:16
basic_string_view< char, etl::char_traits< char > > string_view
Typedef for common character type char
Definition basic_string_view.hpp:704
constexpr auto to_integer(string_view str, Int base=Int(10)) noexcept -> to_integer_result< Int >
Definition to_integer.hpp:93
Definition adjacent_find.hpp:8
constexpr auto stoul(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> unsigned long
Interprets a signed integer value in the string str.
Definition stoi.hpp:64
constexpr auto stoi(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> int
Interprets a signed integer value in the string str.
Definition stoi.hpp:31
constexpr auto stoull(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> unsigned long long
Interprets a signed integer value in the string str.
Definition stoi.hpp:75
constexpr auto stol(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> long
Interprets a signed integer value in the string str.
Definition stoi.hpp:42
constexpr auto stoll(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> long long
Interprets a signed integer value in the string str.
Definition stoi.hpp:53
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14