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// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3#ifndef TETL_STRING_STOD_HPP
4#define TETL_STRING_STOD_HPP
5
6#include <etl/_cstddef/size_t.hpp>
7#include <etl/_iterator/distance.hpp>
8#include <etl/_string/basic_inplace_string.hpp>
9#include <etl/_strings/to_floating_point.hpp>
10
11namespace etl {
12
13/// \brief Interprets a floating point value in a string str.
14/// \param str The string to convert.
15/// \param pos Pointer to integer to store the number of characters used.
16/// \returns The string converted to the specified floating point type.
17/// \ingroup string
18template <size_t Capacity>
19[[nodiscard]] constexpr auto stof(inplace_string<Capacity> const& str, size_t* pos = nullptr) -> float
20{
21 auto const result = etl::strings::to_floating_point<float>({str.data(), str.size()});
22 if (pos != nullptr) {
23 *pos = static_cast<size_t>(etl::distance(str.data(), result.end));
24 }
25 return result.value;
26}
27
28/// \brief Interprets a floating point value in a string str.
29/// \param str The string to convert.
30/// \param pos Pointer to integer to store the number of characters used.
31/// \returns The string converted to the specified floating point type.
32/// \ingroup string
33template <size_t Capacity>
34[[nodiscard]] constexpr auto stod(inplace_string<Capacity> const& str, size_t* pos = nullptr) -> double
35{
36 auto const result = etl::strings::to_floating_point<double>({str.data(), str.size()});
37 if (pos != nullptr) {
38 *pos = static_cast<size_t>(etl::distance(str.data(), result.end));
39 }
40 return result.value;
41}
42
43/// \brief Interprets a floating point value in a string str.
44/// \param str The string to convert.
45/// \param pos Pointer to integer to store the number of characters used.
46/// \returns The string converted to the specified floating point type.
47/// \ingroup string
48template <size_t Capacity>
49[[nodiscard]] constexpr auto stold(inplace_string<Capacity> const& str, size_t* pos = nullptr) -> long double
50{
51 auto const result = etl::strings::to_floating_point<long double>({str.data(), str.size()});
52 if (pos != nullptr) {
53 *pos = static_cast<size_t>(etl::distance(str.data(), result.end));
54 }
55 return result.value;
56}
57
58} // namespace etl
59
60#endif // TETL_STRING_STOD_HPP
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:19
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:49
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:34
Definition find.hpp:9
Definition adjacent_find.hpp:9