26#ifndef INTEGER_DIGITS_INCLUDED
27#define INTEGER_DIGITS_INCLUDED
51 for (
int i = 0; i < 100; ++i) {
57 char *
Write(
int value,
char *to)
const {
58 assert(value >= 0 && value < 100);
59 return std::copy_n(
m_digits[value], 2, to);
75MY_ATTRIBUTE((visibility(
"default")))
78 return writer.
Write(value, to);
90template <
typename T,
int MinDigits,
int MaxDigits,
typename =
void>
92 static_assert(MinDigits < MaxDigits,
"");
93 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
94 "The input should be an unsigned integer.");
97 constexpr int mid = (MinDigits + MaxDigits) / 2;
98 constexpr T pivot =
pow10(mid);
108 for (
int i = 0; i <
n; ++i) x *= 10;
117template <
typename T,
int MinDigits,
int MaxDigits>
119 typename
std::enable_if<MinDigits == MaxDigits>
::type> {
156 *--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:48
constexpr TwoDigitWriter()
Definition: integer_digits.h:50
char m_digits[100][2]
Definition: integer_digits.h:63
char * Write(int value, char *to) const
Definition: integer_digits.h:57
constexpr int count_digits(T x)
Counts the number of base 10 digits in an unsigned integer.
Definition: integer_digits.h:130
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:76
char * write_digits(T number, int digits, char *to)
Writes an unsigned integer of the specified length to a string.
Definition: integer_digits.h:145
Definition: gcs_xcom_synode.h:64
required string type
Definition: replication_group_member_actions.proto:34
static const char digits[]
Definition: stacktrace.cc:644
constexpr int operator()(T) const
Definition: integer_digits.h:120
Functor that calculates the number of digits in an unsigned integer using binary search.
Definition: integer_digits.h:91
constexpr int operator()(T x) const
Definition: integer_digits.h:96
static constexpr T pow10(int n)
Definition: integer_digits.h:106
int n
Definition: xcom_base.cc:509