tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
stod.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_STRING_STOD_HPP
3#define TETL_STRING_STOD_HPP
4
9
10namespace etl {
11
17template <size_t Capacity>
18[[nodiscard]] constexpr auto stof(inplace_string<Capacity> const& str, size_t* pos = nullptr) -> float
19{
20 auto const result = etl::strings::to_floating_point<float>({str.data(), str.size()});
21 if (pos != nullptr) {
22 *pos = static_cast<size_t>(etl::distance(str.data(), result.end));
23 }
24 return result.value;
25}
26
32template <size_t Capacity>
33[[nodiscard]] constexpr auto stod(inplace_string<Capacity> const& str, size_t* pos = nullptr) -> double
34{
35 auto const result = etl::strings::to_floating_point<double>({str.data(), str.size()});
36 if (pos != nullptr) {
37 *pos = static_cast<size_t>(etl::distance(str.data(), result.end));
38 }
39 return result.value;
40}
41
47template <size_t Capacity>
48[[nodiscard]] constexpr auto stold(inplace_string<Capacity> const& str, size_t* pos = nullptr) -> long double
49{
50 auto const result = etl::strings::to_floating_point<long double>({str.data(), str.size()});
51 if (pos != nullptr) {
52 *pos = static_cast<size_t>(etl::distance(str.data(), result.end));
53 }
54 return result.value;
55}
56
57} // namespace etl
58
59#endif // TETL_STRING_STOD_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
constexpr auto stof(inplace_string< Capacity > const &str, size_t *pos=nullptr) -> float
Interprets a floating point value in a string str.
Definition stod.hpp:18
constexpr auto stold(inplace_string< Capacity > const &str, size_t *pos=nullptr) -> long double
Interprets a floating point value in a string str.
Definition stod.hpp:48
constexpr auto stod(inplace_string< Capacity > const &str, size_t *pos=nullptr) -> double
Interprets a floating point value in a string str.
Definition stod.hpp:33
constexpr auto to_floating_point(etl::string_view str) noexcept -> to_floating_point_result< Float >
Definition to_floating_point.hpp:27
Definition adjacent_find.hpp:8
basic_inplace_string< char, Capacity > inplace_string
Typedef for a basic_inplace_string using 'char'.
Definition basic_inplace_string.hpp:1330