2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
11 #define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
14 #include <__charconv/chars_format.h>
15 #include <__charconv/from_chars_result.h>
17 #include <__cstddef/ptrdiff_t.h>
18 #include <__system_error/errc.h>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
25 #include <__undef_macros>
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 #if _LIBCPP_STD_VER >= 17
32 struct __from_chars_result
{
39 _LIBCPP_EXPORTED_FROM_ABI __from_chars_result
<_Fp
> __from_chars_floating_point(
40 _LIBCPP_NOESCAPE
const char* __first
, _LIBCPP_NOESCAPE
const char* __last
, chars_format __fmt
);
42 extern template __from_chars_result
<float> __from_chars_floating_point(
43 _LIBCPP_NOESCAPE
const char* __first
, _LIBCPP_NOESCAPE
const char* __last
, chars_format __fmt
);
45 extern template __from_chars_result
<double> __from_chars_floating_point(
46 _LIBCPP_NOESCAPE
const char* __first
, _LIBCPP_NOESCAPE
const char* __last
, chars_format __fmt
);
49 _LIBCPP_HIDE_FROM_ABI from_chars_result
50 __from_chars(const char* __first
, const char* __last
, _Fp
& __value
, chars_format __fmt
) {
51 __from_chars_result
<_Fp
> __r
= std::__from_chars_floating_point
<_Fp
>(__first
, __last
, __fmt
);
52 if (__r
.__ec
!= errc::invalid_argument
)
53 __value
= __r
.__value
;
54 return {__first
+ __r
.__n
, __r
.__ec
};
57 _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI
inline from_chars_result
58 from_chars(const char* __first
, const char* __last
, float& __value
, chars_format __fmt
= chars_format::general
) {
59 return std::__from_chars
<float>(__first
, __last
, __value
, __fmt
);
62 _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI
inline from_chars_result
63 from_chars(const char* __first
, const char* __last
, double& __value
, chars_format __fmt
= chars_format::general
) {
64 return std::__from_chars
<double>(__first
, __last
, __value
, __fmt
);
67 #endif // _LIBCPP_STD_VER >= 17
69 _LIBCPP_END_NAMESPACE_STD
73 #endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H