to_chars.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, long double value,
  78. chars_format fmt = chars_format::general) noexcept;
  79. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, float value,
  80. chars_format fmt, int precision) noexcept;
  81. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, double value,
  82. chars_format fmt, int precision) noexcept;
  83. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, long double value,
  84. chars_format fmt, int precision) noexcept;
  85. #ifdef BOOST_CHARCONV_HAS_FLOAT128
  86. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, __float128 value,
  87. chars_format fmt = chars_format::general) noexcept;
  88. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, __float128 value,
  89. chars_format fmt, int precision) noexcept;
  90. #endif
  91. #ifdef BOOST_CHARCONV_HAS_FLOAT16
  92. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float16_t value,
  93. chars_format fmt = chars_format::general) noexcept;
  94. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float16_t value,
  95. chars_format fmt, int precision) noexcept;
  96. #endif
  97. #ifdef BOOST_CHARCONV_HAS_FLOAT32
  98. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float32_t value,
  99. chars_format fmt = chars_format::general) noexcept;
  100. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float32_t value,
  101. chars_format fmt, int precision) noexcept;
  102. #endif
  103. #ifdef BOOST_CHARCONV_HAS_FLOAT64
  104. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float64_t value,
  105. chars_format fmt = chars_format::general) noexcept;
  106. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float64_t value,
  107. chars_format fmt, int precision) noexcept;
  108. #endif
  109. #if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_FLOAT128)
  110. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float128_t value,
  111. chars_format fmt = chars_format::general) noexcept;
  112. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::float128_t value,
  113. chars_format fmt, int precision) noexcept;
  114. #endif
  115. #ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
  116. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::bfloat16_t value,
  117. chars_format fmt = chars_format::general) noexcept;
  118. BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::bfloat16_t value,
  119. chars_format fmt, int precision) noexcept;
  120. #endif
  121. } // namespace charconv
  122. } // namespace boost
  123. #endif // #ifndef BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED