tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
to_string.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_STRING_TO_STRING_HPP
4#define TETL_STRING_TO_STRING_HPP
5
10
11namespace etl {
12
13namespace detail {
14
15template <etl::size_t Capacity, typename Int>
16constexpr auto to_string(Int val) -> etl::inplace_string<Capacity>
17{
18 char buffer[Capacity]{};
19 auto const res = etl::strings::from_integer<Int>(val, etl::data(buffer), Capacity, 10);
21 return etl::inplace_string<Capacity>{etl::data(buffer), res.end};
22}
23
24} // namespace detail
25
27template <etl::size_t Capacity>
28[[nodiscard]] constexpr auto to_string(int value) noexcept -> etl::inplace_string<Capacity>
29{
30 return etl::detail::to_string<Capacity, int>(value);
31}
32
34template <etl::size_t Capacity>
35[[nodiscard]] constexpr auto to_string(long value) noexcept -> etl::inplace_string<Capacity>
36{
37 return etl::detail::to_string<Capacity, long>(value);
38}
39
41template <etl::size_t Capacity>
42[[nodiscard]] constexpr auto to_string(long long value) noexcept -> etl::inplace_string<Capacity>
43{
44 return etl::detail::to_string<Capacity, long long>(value);
45}
46
48template <etl::size_t Capacity>
49[[nodiscard]] constexpr auto to_string(unsigned value) noexcept -> etl::inplace_string<Capacity>
50{
51 return etl::detail::to_string<Capacity, unsigned>(value);
52}
53
55template <etl::size_t Capacity>
56[[nodiscard]] constexpr auto to_string(unsigned long value) noexcept -> etl::inplace_string<Capacity>
57{
58 return etl::detail::to_string<Capacity, unsigned long>(value);
59}
60
62template <etl::size_t Capacity>
63[[nodiscard]] constexpr auto to_string(unsigned long long value) noexcept -> etl::inplace_string<Capacity>
64{
65 return etl::detail::to_string<Capacity, unsigned long long>(value);
66}
67
68} // namespace etl
69
70#endif // TETL_STRING_TO_STRING_HPP
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto data(C &c) noexcept(noexcept(c.data())) -> decltype(c.data())
Returns a pointer to the block of memory containing the elements of the container.
Definition data.hpp:11
@ none
Definition from_integer.hpp:20
constexpr auto from_integer(Int num, char *str, size_t length, int base) -> from_integer_result
Definition from_integer.hpp:30
Definition adjacent_find.hpp:8
constexpr auto to_string(int value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:28
basic_inplace_string< char, Capacity > inplace_string
Typedef for a basic_inplace_string using 'char'.
Definition basic_inplace_string.hpp:1330