tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
from_chars.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CHARCONV_FROM_CHARS_HPP
4#define TETL_CHARCONV_FROM_CHARS_HPP
5
11
12namespace etl {
13
16 char const* ptr{nullptr};
18
19 [[nodiscard]] constexpr explicit operator bool() const noexcept { return ec == etl::errc{}; }
20
21 friend auto operator==(from_chars_result const&, from_chars_result const&) -> bool = default;
22};
23
30template <integral Int>
31 requires(not same_as<Int, bool>)
32[[nodiscard]] constexpr auto from_chars(char const* first, char const* last, Int& value, int base = 10)
34{
35 constexpr auto options = strings::to_integer_options{.skip_whitespace = false, .check_overflow = true};
36 auto const [end, err, val] = strings::to_integer<Int, options>({first, last}, static_cast<Int>(base));
37
39 return from_chars_result{.ptr = first, .ec = errc::result_out_of_range};
40 }
42 return from_chars_result{.ptr = first, .ec = errc::invalid_argument};
43 }
44
45 value = val;
46 return from_chars_result{.ptr = end, .ec = {}};
47}
48
49} // namespace etl
50
51#endif // TETL_CHARCONV_FROM_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 end(C &c) -> decltype(c.end())
Returns an iterator to the end (i.e. the element after the last element) of the given container c or ...
Definition end.hpp:14
@ overflow
Definition to_integer.hpp:82
@ invalid_input
Definition to_integer.hpp:81
constexpr auto to_integer(string_view str, Int base=Int(10)) noexcept -> to_integer_result< Int >
Definition to_integer.hpp:93
Definition adjacent_find.hpp:8
constexpr auto from_chars(char const *first, char const *last, Int &value, int base=10) -> from_chars_result
Analyzes the character sequence [first,last) for a pattern described below. If no characters match th...
Definition from_chars.hpp:32
errc
The scoped enumeration etl::errc defines the values of portable error conditions that correspond to t...
Definition errc.hpp:12
@ result_out_of_range
Definition errc.hpp:80
@ invalid_argument
Definition errc.hpp:41
Primitive numerical input conversion.
Definition from_chars.hpp:15
friend auto operator==(from_chars_result const &, from_chars_result const &) -> bool=default
etl::errc ec
Definition from_chars.hpp:17
char const * ptr
Definition from_chars.hpp:16
Definition to_integer.hpp:74