add Char template parameter to to_string
This commit is contained in:
parent
f674434a67
commit
8e82d7a757
@ -639,7 +639,7 @@ FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
|
|||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
constexpr basic_string_view<typename S::char_type> str = S();
|
constexpr basic_string_view<typename S::char_type> str = S();
|
||||||
if (str.size() == 2 && str[0] == '{' && str[1] == '}')
|
if (str.size() == 2 && str[0] == '{' && str[1] == '}')
|
||||||
return fmt::to_string(detail::first(args...));
|
return fmt::to_string<typename S::char_type>(detail::first(args...));
|
||||||
constexpr auto compiled = detail::compile<Args...>(S());
|
constexpr auto compiled = detail::compile<Args...>(S());
|
||||||
return format(compiled, std::forward<Args>(args)...);
|
return format(compiled, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3481,21 +3481,23 @@ arg_join<detail::iterator_t<Range>, detail::sentinel_t<Range>, wchar_t> join(
|
|||||||
std::string answer = fmt::to_string(42);
|
std::string answer = fmt::to_string(42);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
template <typename Char = char, typename T,
|
||||||
inline std::string to_string(const T& value) {
|
FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||||
std::string result;
|
inline std::basic_string<Char> to_string(const T& value) {
|
||||||
detail::write<char>(std::back_inserter(result), value);
|
std::basic_string<Char> result;
|
||||||
|
detail::write<Char>(std::back_inserter(result), value);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
template <typename Char = char, typename T,
|
||||||
inline std::string to_string(T value) {
|
FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||||
|
inline std::basic_string<Char> to_string(T value) {
|
||||||
// The buffer should be large enough to store the number including the sign or
|
// The buffer should be large enough to store the number including the sign or
|
||||||
// "false" for bool.
|
// "false" for bool.
|
||||||
constexpr int max_size = detail::digits10<T>() + 2;
|
constexpr int max_size = detail::digits10<T>() + 2;
|
||||||
char buffer[max_size > 5 ? max_size : 5];
|
Char buffer[max_size > 5 ? max_size : 5];
|
||||||
char* begin = buffer;
|
Char* begin = buffer;
|
||||||
return std::string(begin, detail::write<char>(begin, value));
|
return std::basic_string<Char>(begin, detail::write<Char>(begin, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user