charconv 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef _LIBCPP_CHARCONV
  10. #define _LIBCPP_CHARCONV
  11. /*
  12. charconv synopsis
  13. namespace std {
  14. // floating-point format for primitive numerical conversion
  15. enum class chars_format {
  16. scientific = unspecified,
  17. fixed = unspecified,
  18. hex = unspecified,
  19. general = fixed | scientific
  20. };
  21. // 23.20.2, primitive numerical output conversion
  22. struct to_chars_result {
  23. char* ptr;
  24. errc ec;
  25. friend bool operator==(const to_chars_result&, const to_chars_result&) = default; // since C++20
  26. constexpr explicit operator bool() const noexcept { return ec == errc{}; } // since C++26
  27. };
  28. constexpr to_chars_result to_chars(char* first, char* last, see below value,
  29. int base = 10); // constexpr since C++23
  30. to_chars_result to_chars(char* first, char* last, bool value,
  31. int base = 10) = delete;
  32. to_chars_result to_chars(char* first, char* last, float value);
  33. to_chars_result to_chars(char* first, char* last, double value);
  34. to_chars_result to_chars(char* first, char* last, long double value);
  35. to_chars_result to_chars(char* first, char* last, float value,
  36. chars_format fmt);
  37. to_chars_result to_chars(char* first, char* last, double value,
  38. chars_format fmt);
  39. to_chars_result to_chars(char* first, char* last, long double value,
  40. chars_format fmt);
  41. to_chars_result to_chars(char* first, char* last, float value,
  42. chars_format fmt, int precision);
  43. to_chars_result to_chars(char* first, char* last, double value,
  44. chars_format fmt, int precision);
  45. to_chars_result to_chars(char* first, char* last, long double value,
  46. chars_format fmt, int precision);
  47. // 23.20.3, primitive numerical input conversion
  48. struct from_chars_result {
  49. const char* ptr;
  50. errc ec;
  51. friend bool operator==(const from_chars_result&, const from_chars_result&) = default; // since C++20
  52. constexpr explicit operator bool() const noexcept { return ec == errc{}; } // since C++26
  53. };
  54. constexpr from_chars_result from_chars(const char* first, const char* last,
  55. see below& value, int base = 10); // constexpr since C++23
  56. } // namespace std
  57. */
  58. #include <__assert> // all public C++ headers provide the assertion handler
  59. #include <__charconv/chars_format.h>
  60. #include <__charconv/from_chars_integral.h>
  61. #include <__charconv/from_chars_result.h>
  62. #include <__charconv/tables.h>
  63. #include <__charconv/to_chars.h>
  64. #include <__charconv/to_chars_base_10.h>
  65. #include <__charconv/to_chars_floating_point.h>
  66. #include <__charconv/to_chars_integral.h>
  67. #include <__charconv/to_chars_result.h>
  68. #include <__charconv/traits.h>
  69. #include <__config>
  70. #include <__system_error/errc.h>
  71. #include <cmath> // for log2f
  72. #include <cstdint>
  73. #include <limits>
  74. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  75. # pragma GCC system_header
  76. #endif
  77. _LIBCPP_BEGIN_NAMESPACE_STD
  78. _LIBCPP_END_NAMESPACE_STD
  79. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  80. # include <concepts>
  81. # include <cstdlib>
  82. # include <cstring>
  83. # include <iosfwd>
  84. # include <type_traits>
  85. #endif
  86. #endif // _LIBCPP_CHARCONV