to_chars.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright 2022 Peter Dimov
  2. // Copyright 2023 Matt Borland
  3. // Copyright 2023 Junekey Jeon
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED
  7. #define BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED
  8. #include <boost/charconv/detail/to_chars_integer_impl.hpp>
  9. #include <boost/charconv/detail/to_chars_result.hpp>
  10. #include <boost/charconv/config.hpp>
  11. #include <boost/charconv/chars_format.hpp>
  12. namespace boost {
  13. namespace charconv {
  14. // integer overloads
  15. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, bool value, int base) noexcept = delete;
  16. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, char value, int base = 10) noexcept
  17. {
  18. return detail::to_chars_int(first, last, value, base);
  19. }
  20. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, signed char value, int base = 10) noexcept
  21. {
  22. return detail::to_chars_int(first, last, value, base);
  23. }
  24. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, unsigned char value, int base = 10) noexcept
  25. {
  26. return detail::to_chars_int(first, last, value, base);
  27. }
  28. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, short value, int base = 10) noexcept
  29. {
  30. return detail::to_chars_int(first, last, value, base);
  31. }
  32. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, unsigned short value, int base = 10) noexcept
  33. {
  34. return detail::to_chars_int(first, last, value, base);
  35. }
  36. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, int value, int base = 10) noexcept
  37. {
  38. return detail::to_chars_int(first, last, value, base);
  39. }
  40. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, unsigned int value, int base = 10) noexcept
  41. {
  42. return detail::to_chars_int(first, last, value, base);
  43. }
  44. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, long value, int base = 10) noexcept
  45. {
  46. return detail::to_chars_int(first, last, value, base);
  47. }
  48. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, unsigned long value, int base = 10) noexcept
  49. {
  50. return detail::to_chars_int(first, last, value, base);
  51. }
  52. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, long long value, int base = 10) noexcept
  53. {
  54. return detail::to_chars_int(first, last, value, base);
  55. }
  56. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, unsigned long long value, int base = 10) noexcept
  57. {
  58. return detail::to_chars_int(first, last, value, base);
  59. }
  60. #ifdef BOOST_CHARCONV_HAS_INT128
  61. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, boost::int128_type value, int base = 10) noexcept
  62. {
  63. return detail::to_chars128(first, last, value, base);
  64. }
  65. BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, boost::uint128_type value, int base = 10) noexcept
  66. {
  67. return detail::to_chars128(first, last, value, base);
  68. }
  69. #endif
  70. //----------------------------------------------------------------------------------------------------------------------
  71. // Floating Point
  72. //----------------------------------------------------------------------------------------------------------------------
  73. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, float value,
  74. chars_format fmt = chars_format::general) noexcept;
  75. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, double value,
  76. chars_format fmt = chars_format::general) noexcept;
  77. #ifndef BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE
  78. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, long double value,
  79. chars_format fmt = chars_format::general) noexcept;
  80. #endif
  81. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, float value,
  82. chars_format fmt, int precision) noexcept;
  83. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, double value,
  84. chars_format fmt, int precision) noexcept;
  85. #ifndef BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE
  86. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, long double value,
  87. chars_format fmt, int precision) noexcept;
  88. #endif
  89. #ifdef BOOST_CHARCONV_HAS_QUADMATH
  90. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, __float128 value,
  91. chars_format fmt = chars_format::general) noexcept;
  92. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, __float128 value,
  93. chars_format fmt, int precision) noexcept;
  94. #endif
  95. #ifdef BOOST_CHARCONV_HAS_FLOAT16
  96. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float16_t value,
  97. chars_format fmt = chars_format::general) noexcept;
  98. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float16_t value,
  99. chars_format fmt, int precision) noexcept;
  100. #endif
  101. #ifdef BOOST_CHARCONV_HAS_FLOAT32
  102. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float32_t value,
  103. chars_format fmt = chars_format::general) noexcept;
  104. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float32_t value,
  105. chars_format fmt, int precision) noexcept;
  106. #endif
  107. #ifdef BOOST_CHARCONV_HAS_FLOAT64
  108. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float64_t value,
  109. chars_format fmt = chars_format::general) noexcept;
  110. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float64_t value,
  111. chars_format fmt, int precision) noexcept;
  112. #endif
  113. #if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_QUADMATH)
  114. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float128_t value,
  115. chars_format fmt = chars_format::general) noexcept;
  116. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float128_t value,
  117. chars_format fmt, int precision) noexcept;
  118. #endif
  119. #ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
  120. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::bfloat16_t value,
  121. chars_format fmt = chars_format::general) noexcept;
  122. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::bfloat16_t value,
  123. chars_format fmt, int precision) noexcept;
  124. #endif
  125. } // namespace charconv
  126. } // namespace boost
  127. #endif // #ifndef BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED