forked from boostorg/beast
Add to_static_string:
This function converts integers to their decimal representation as a static string. In addition, static_string::resize no longer initializes characters if the new size is larger.
This commit is contained in:
@@ -31,6 +31,8 @@ namespace beast {
|
||||
imposes a natural small upper limit on the size of a value.
|
||||
|
||||
@note The stored string is always null-terminated.
|
||||
|
||||
@see @ref to_static_string
|
||||
*/
|
||||
template<
|
||||
std::size_t N,
|
||||
@@ -783,13 +785,10 @@ public:
|
||||
/** Changes the number of characters stored.
|
||||
|
||||
If the resulting string is larger, the new
|
||||
characters are initialized to zero.
|
||||
characters are uninitialized.
|
||||
*/
|
||||
void
|
||||
resize(std::size_t n)
|
||||
{
|
||||
resize(n, 0);
|
||||
}
|
||||
resize(std::size_t n);
|
||||
|
||||
/** Changes the number of characters stored.
|
||||
|
||||
@@ -1098,6 +1097,23 @@ operator<<(std::basic_ostream<CharT, Traits>& os,
|
||||
beast::basic_string_view<CharT, Traits>>(str);
|
||||
}
|
||||
|
||||
//
|
||||
// Numeric conversions
|
||||
//
|
||||
|
||||
/** Returns a static string representing an integer as a decimal.
|
||||
|
||||
@param x The signed or unsigned integer to convert.
|
||||
This must be an integral type.
|
||||
|
||||
@return A @ref static_string with an implementation defined
|
||||
maximum size large enough to hold the longest possible decimal
|
||||
representation of any integer of the given type.
|
||||
*/
|
||||
template<class Integer>
|
||||
static_string<detail::max_digits(sizeof(Integer))>
|
||||
to_static_string(Integer x);
|
||||
|
||||
} // beast
|
||||
|
||||
#include <beast/core/impl/static_string.ipp>
|
||||
|
||||
Reference in New Issue
Block a user