Use std::to_string when doing ascii conversions

It's fast, it works, it's correct. No need for
any of the fancy stuff when all we want is int
to ascii string.

Currently on my system the implementation of
std::to_string is *very* similar to mine, but
it doesn't have the overhead of calculating
ASCII offsets because their lookup already
contains ASCII values.
This commit is contained in:
King_DuckZ 2021-06-07 23:10:35 +02:00
parent e1599820b4
commit 9919f1aeb2

View file

@ -24,6 +24,8 @@
#include <string_view>
#include <array>
#define DHANDY_INTCONV_USE_STDSTRING
namespace dhandy {
namespace implem {
template <typename T, typename F, typename Tr, bool FromInt=std::is_integral_v<F>>
@ -42,6 +44,14 @@ namespace dhandy {
return IntConvString<Tr>{retval.begin(), retval.end() - 1};
}
};
#if defined(DHANDY_INTCONV_USE_STDSTRING)
template <typename F, typename C>
struct IntConv<IntConvString<ASCIITranslator<C>>, F, ASCIITranslator<C>, true> {
static IntConvString<ASCIITranslator<C>> conv (const F& in) {
return std::to_string(in);
}
};
#endif
template <typename F, typename Tr>
struct IntConv<IntConvStringView<Tr>, F, Tr, true> {
consteval static IntConvStringView<Tr> conv (const F& in) {