Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | // -*- C++ -*- |
|---|---|
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 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 |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H |
| 11 | #define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H |
| 12 | |
| 13 | #include <__assert> |
| 14 | #include <__charconv/chars_format.h> |
| 15 | #include <__charconv/from_chars_result.h> |
| 16 | #include <__config> |
| 17 | #include <__cstddef/ptrdiff_t.h> |
| 18 | #include <__system_error/errc.h> |
| 19 | |
| 20 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 21 | # pragma GCC system_header |
| 22 | #endif |
| 23 | |
| 24 | _LIBCPP_PUSH_MACROS |
| 25 | #include <__undef_macros> |
| 26 | |
| 27 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 28 | |
| 29 | #if _LIBCPP_STD_VER >= 17 |
| 30 | |
| 31 | template <class _Fp> |
| 32 | struct __from_chars_result { |
| 33 | _Fp __value; |
| 34 | ptrdiff_t __n; |
| 35 | errc __ec; |
| 36 | }; |
| 37 | |
| 38 | template <class _Fp> |
| 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); |
| 41 | |
| 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); |
| 44 | |
| 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); |
| 47 | |
| 48 | template <class _Fp> |
| 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}; |
| 55 | } |
| 56 | |
| 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); |
| 60 | } |
| 61 | |
| 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); |
| 65 | } |
| 66 | |
| 67 | #endif // _LIBCPP_STD_VER >= 17 |
| 68 | |
| 69 | _LIBCPP_END_NAMESPACE_STD |
| 70 | |
| 71 | _LIBCPP_POP_MACROS |
| 72 | |
| 73 | #endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H |
| 74 |
Warning: This file is not a C or C++ file. It does not have highlighting.
