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// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_STRING_TO_STRING_HPP
5#define TETL_STRING_TO_STRING_HPP
6
7#include <etl/_contracts/check.hpp>
8#include <etl/_iterator/data.hpp>
9#include <etl/_string/basic_inplace_string.hpp>
10#include <etl/_strings/from_integer.hpp>
11
12namespace etl {
13
14namespace detail {
15
16template <etl::size_t Capacity, typename Int>
17constexpr auto to_string(Int val) -> etl::inplace_string<Capacity>
18{
19 char buffer[Capacity]{};
20 auto const res = etl::strings::from_integer<Int>(val, etl::data(buffer), Capacity, 10);
21 TETL_PRECONDITION(res.error == etl::strings::from_integer_error::none);
22 return etl::inplace_string<Capacity>{etl::data(buffer), res.end};
23}
24
25} // namespace detail
26
27/// \brief Converts a numeric value to etl::inplace_string.
28template <etl::size_t Capacity>
29[[nodiscard]] constexpr auto to_string(int value) noexcept -> etl::inplace_string<Capacity>
30{
31 return etl::detail::to_string<Capacity, int>(value);
32}
33
34/// \brief Converts a numeric value to etl::inplace_string.
35template <etl::size_t Capacity>
36[[nodiscard]] constexpr auto to_string(long value) noexcept -> etl::inplace_string<Capacity>
37{
38 return etl::detail::to_string<Capacity, long>(value);
39}
40
41/// \brief Converts a numeric value to etl::inplace_string.
42template <etl::size_t Capacity>
43[[nodiscard]] constexpr auto to_string(long long value) noexcept -> etl::inplace_string<Capacity>
44{
45 return etl::detail::to_string<Capacity, long long>(value);
46}
47
48/// \brief Converts a numeric value to etl::inplace_string.
49template <etl::size_t Capacity>
50[[nodiscard]] constexpr auto to_string(unsigned value) noexcept -> etl::inplace_string<Capacity>
51{
52 return etl::detail::to_string<Capacity, unsigned>(value);
53}
54
55/// \brief Converts a numeric value to etl::inplace_string.
56template <etl::size_t Capacity>
57[[nodiscard]] constexpr auto to_string(unsigned long value) noexcept -> etl::inplace_string<Capacity>
58{
59 return etl::detail::to_string<Capacity, unsigned long>(value);
60}
61
62/// \brief Converts a numeric value to etl::inplace_string.
63template <etl::size_t Capacity>
64[[nodiscard]] constexpr auto to_string(unsigned long long value) noexcept -> etl::inplace_string<Capacity>
65{
66 return etl::detail::to_string<Capacity, unsigned long long>(value);
67}
68
69} // namespace etl
70
71#endif // TETL_STRING_TO_STRING_HPP
Definition find.hpp:9
Definition adjacent_find.hpp:9
constexpr auto to_string(long long value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:43
constexpr auto to_string(unsigned value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:50
constexpr auto to_string(unsigned long value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:57
constexpr auto to_string(unsigned long long value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:64
constexpr auto to_string(long value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:36
constexpr auto to_string(int value) noexcept -> etl::inplace_string< Capacity >
Converts a numeric value to etl::inplace_string.
Definition to_string.hpp:29