25#ifndef INTEGER_DIGITS_INCLUDED
26#define INTEGER_DIGITS_INCLUDED
48 for (
int i = 0; i < 100; ++i) {
54 char *
Write(
int value,
char *to)
const {
55 assert(value >= 0 && value < 100);
56 return std::copy_n(
m_digits[value], 2, to);
74 return writer.
Write(value, to);
86template <
typename T,
int MinDigits,
int MaxDigits,
typename =
void>
88 static_assert(MinDigits < MaxDigits,
"");
89 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
90 "The input should be an unsigned integer.");
93 constexpr int mid = (MinDigits + MaxDigits) / 2;
94 constexpr T pivot =
pow10(mid);
104 for (
int i = 0; i <
n; ++i) x *= 10;
113template <
typename T,
int MinDigits,
int MaxDigits>
115 typename
std::enable_if<MinDigits == MaxDigits>
::type> {
152 *--pos =
'0' + number % 10;
Helper class for write_two_digits(), which creates a table that maps every integer from 0 to 99 to a ...
Definition: integer_digits.h:45
constexpr TwoDigitWriter()
Definition: integer_digits.h:47
char m_digits[100][2]
Definition: integer_digits.h:60
char * Write(int value, char *to) const
Definition: integer_digits.h:54
constexpr int count_digits(T x)
Counts the number of base 10 digits in an unsigned integer.
Definition: integer_digits.h:126
char * write_two_digits(int value, char *to)
Writes an integer, which is between 0 (inclusive) and 100 (exclusive), to a string in base 10.
Definition: integer_digits.h:72
char * write_digits(T number, int digits, char *to)
Writes an unsigned integer of the specified length to a string.
Definition: integer_digits.h:141
Definition: varlen_sort.h:183
required string type
Definition: replication_group_member_actions.proto:33
static const char digits[]
Definition: stacktrace.cc:597
constexpr int operator()(T) const
Definition: integer_digits.h:116
Functor that calculates the number of digits in an unsigned integer using binary search.
Definition: integer_digits.h:87
constexpr int operator()(T x) const
Definition: integer_digits.h:92
static constexpr T pow10(int n)
Definition: integer_digits.h:102
int n
Definition: xcom_base.cc:508