tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
to_chars.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CHARCONV_TO_CHARS_HPP
4#define TETL_CHARCONV_TO_CHARS_HPP
5
12
13namespace etl {
14
17 char const* ptr{nullptr};
19
20 [[nodiscard]] constexpr explicit operator bool() const noexcept { return ec == etl::errc{}; }
21
22 friend auto operator==(to_chars_result const&, to_chars_result const&) -> bool = default;
23};
24
34template <integral T>
35 requires(not same_as<T, bool>)
36[[nodiscard]] constexpr auto to_chars(char* first, char* last, T val, int base = 10) -> to_chars_result
37{
38 constexpr auto options = strings::from_integer_options{.terminate_with_null = false};
39
40 auto const len = static_cast<etl::size_t>(etl::distance(first, last));
41 auto const res = strings::from_integer<T, options>(val, first, len, base);
42 if (res.error == strings::from_integer_error::none) {
43 return to_chars_result{res.end, {}};
44 }
45 return to_chars_result{
46 .ptr = last,
48 };
49}
50
51[[nodiscard]] constexpr auto to_chars(char*, char*, bool, int = 10) -> to_chars_result = delete;
52
53} // namespace etl
54
55#endif // TETL_CHARCONV_TO_CHARS_HPP
The concept same_as<T, U> is satisfied if and only if T and U denote the same type....
Definition same_as.hpp:19
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
@ 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_chars(char *first, char *last, T val, int base=10) -> to_chars_result
Converts value into a character string by successively filling the range [first, last),...
Definition to_chars.hpp:36
errc
The scoped enumeration etl::errc defines the values of portable error conditions that correspond to t...
Definition errc.hpp:12
@ value_too_large
Definition errc.hpp:89
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
Definition from_integer.hpp:15
Primitive numerical output conversion.
Definition to_chars.hpp:16
etl::errc ec
Definition to_chars.hpp:18
char const * ptr
Definition to_chars.hpp:17
friend auto operator==(to_chars_result const &, to_chars_result const &) -> bool=default