Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | eb8650a | 2021-11-17 21:25:01 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 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 |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_CHARCONV |
| 11 | #define _LIBCPP_CHARCONV |
| 12 | |
| 13 | /* |
| 14 | charconv synopsis |
| 15 | |
| 16 | namespace std { |
| 17 | |
| 18 | // floating-point format for primitive numerical conversion |
| 19 | enum class chars_format { |
| 20 | scientific = unspecified, |
| 21 | fixed = unspecified, |
| 22 | hex = unspecified, |
| 23 | general = fixed | scientific |
| 24 | }; |
| 25 | |
| 26 | // 23.20.2, primitive numerical output conversion |
| 27 | struct to_chars_result { |
| 28 | char* ptr; |
| 29 | errc ec; |
Mark de Wever | 3624c4d | 2021-10-23 16:28:31 | [diff] [blame] | 30 | friend bool operator==(const to_chars_result&, const to_chars_result&) = default; // since C++20 |
Mark de Wever | 92ac360 | 2023-06-17 11:19:58 | [diff] [blame] | 31 | constexpr explicit operator bool() const noexcept { return ec == errc{}; } // since C++26 |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 32 | }; |
| 33 | |
Mark de Wever | a1e13a8 | 2022-08-06 08:47:53 | [diff] [blame] | 34 | constexpr to_chars_result to_chars(char* first, char* last, see below value, |
| 35 | int base = 10); // constexpr since C++23 |
Konstantin Varlamov | a59c1a2 | 2021-10-15 15:40:42 | [diff] [blame] | 36 | to_chars_result to_chars(char* first, char* last, bool value, |
| 37 | int base = 10) = delete; |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 38 | |
| 39 | to_chars_result to_chars(char* first, char* last, float value); |
| 40 | to_chars_result to_chars(char* first, char* last, double value); |
| 41 | to_chars_result to_chars(char* first, char* last, long double value); |
| 42 | |
| 43 | to_chars_result to_chars(char* first, char* last, float value, |
| 44 | chars_format fmt); |
| 45 | to_chars_result to_chars(char* first, char* last, double value, |
| 46 | chars_format fmt); |
| 47 | to_chars_result to_chars(char* first, char* last, long double value, |
| 48 | chars_format fmt); |
| 49 | |
| 50 | to_chars_result to_chars(char* first, char* last, float value, |
| 51 | chars_format fmt, int precision); |
| 52 | to_chars_result to_chars(char* first, char* last, double value, |
| 53 | chars_format fmt, int precision); |
| 54 | to_chars_result to_chars(char* first, char* last, long double value, |
| 55 | chars_format fmt, int precision); |
| 56 | |
| 57 | // 23.20.3, primitive numerical input conversion |
| 58 | struct from_chars_result { |
| 59 | const char* ptr; |
| 60 | errc ec; |
Mark de Wever | 3624c4d | 2021-10-23 16:28:31 | [diff] [blame] | 61 | friend bool operator==(const from_chars_result&, const from_chars_result&) = default; // since C++20 |
Mark de Wever | 92ac360 | 2023-06-17 11:19:58 | [diff] [blame] | 62 | constexpr explicit operator bool() const noexcept { return ec == errc{}; } // since C++26 |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 63 | }; |
| 64 | |
Mark de Wever | a1e13a8 | 2022-08-06 08:47:53 | [diff] [blame] | 65 | constexpr from_chars_result from_chars(const char* first, const char* last, |
| 66 | see below& value, int base = 10); // constexpr since C++23 |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 67 | |
Michael Jones | 6c4267f | 2024-10-21 22:04:06 | [diff] [blame] | 68 | from_chars_result from_chars(const char* first, const char* last, |
| 69 | float& value, chars_format fmt); |
| 70 | |
| 71 | from_chars_result from_chars(const char* first, const char* last, |
| 72 | double& value, chars_format fmt); |
| 73 | |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 74 | } // namespace std |
| 75 | |
| 76 | */ |
| 77 | |
Nikolas Klauser | b9a2658 | 2024-12-21 12:01:48 | [diff] [blame] | 78 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
Nikolas Klauser | 750da48 | 2025-04-09 13:00:46 | [diff] [blame] | 79 | # include <__cxx03/__config> |
Nikolas Klauser | b9a2658 | 2024-12-21 12:01:48 | [diff] [blame] | 80 | #else |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 81 | # include <__config> |
Nikolas Klauser | d5c654b | 2024-04-14 13:52:56 | [diff] [blame] | 82 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 83 | # if _LIBCPP_STD_VER >= 17 |
| 84 | # include <__charconv/chars_format.h> |
| 85 | # include <__charconv/from_chars_floating_point.h> |
| 86 | # include <__charconv/from_chars_integral.h> |
| 87 | # include <__charconv/from_chars_result.h> |
| 88 | # include <__charconv/tables.h> |
| 89 | # include <__charconv/to_chars.h> |
| 90 | # include <__charconv/to_chars_base_10.h> |
| 91 | # include <__charconv/to_chars_floating_point.h> |
| 92 | # include <__charconv/to_chars_integral.h> |
| 93 | # include <__charconv/to_chars_result.h> |
| 94 | # include <__charconv/traits.h> |
| 95 | # endif // _LIBCPP_STD_VER >= 17 |
Nikolas Klauser | d5c654b | 2024-04-14 13:52:56 | [diff] [blame] | 96 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 97 | # include <version> |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 98 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 99 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 100 | # pragma GCC system_header |
| 101 | # endif |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 102 | |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 103 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 104 | |
Zhihao Yuan | d274896 | 2018-08-01 02:38:30 | [diff] [blame] | 105 | _LIBCPP_END_NAMESPACE_STD |
| 106 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 107 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 108 | # include <cmath> |
| 109 | # include <concepts> |
| 110 | # include <cstddef> |
| 111 | # include <cstdint> |
| 112 | # include <cstdlib> |
| 113 | # include <cstring> |
| 114 | # include <iosfwd> |
| 115 | # include <limits> |
Louis Dionne | 9474e09 | 2024-12-13 19:17:56 | [diff] [blame] | 116 | # include <new> |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 117 | # include <type_traits> |
| 118 | # endif |
Nikolas Klauser | b9a2658 | 2024-12-21 12:01:48 | [diff] [blame] | 119 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
Mark de Wever | e31c2a1 | 2022-09-02 15:53:28 | [diff] [blame] | 120 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 121 | #endif // _LIBCPP_CHARCONV |