[libc] [libcxx] [llvm] [libcxx][libc] Hand in Hand PoC with from_chars (PR #91651)
Louis Dionne via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 12:30:26 PDT 2024
================
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
+#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
+
+#include <__assert>
+#include <__charconv/chars_format.h>
+#include <__charconv/from_chars_result.h>
+#include <__config>
+#include <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 17
+
+template <class _Fp>
+struct __from_chars_result {
+ _Fp __value;
+ ptrdiff_t __n;
+ errc __ec;
+};
+
+template <class _Fp>
+_LIBCPP_EXPORTED_FROM_ABI [[gnu::pure]] __from_chars_result<_Fp> __from_chars_floating_point(
+ [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+
+extern template __from_chars_result<float> __from_chars_floating_point(
+ [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+
+extern template __from_chars_result<double> __from_chars_floating_point(
+ [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
----------------
ldionne wrote:
This works, but FWIW it would be strictly simpler to use
```
_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<float> __from_chars_float(...);
_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<double> __from_chars_double(...);
```
That way, no need to think about whether the `EXPORTED_FROM_ABI` attribute is inherited by the external template declaration. It also simplifies the `.cpp` file since you don't need any explicit template instantiation. It's less "cute", but it's simpler overall.
https://github.com/llvm/llvm-project/pull/91651
More information about the llvm-commits
mailing list