[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / libcxx / include / __charconv / from_chars_floating_point.h
blob811e518a81db70c92bb581c56e85a84ed0aa6201
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
11 #define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
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>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
22 #endif
24 _LIBCPP_PUSH_MACROS
25 #include <__undef_macros>
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 #if _LIBCPP_STD_VER >= 17
31 template <class _Fp>
32 struct __from_chars_result {
33 _Fp __value;
34 ptrdiff_t __n;
35 errc __ec;
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);
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);
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};
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
71 _LIBCPP_POP_MACROS
73 #endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H