26#ifndef INTEGER_DIGITS_INCLUDED
27#define INTEGER_DIGITS_INCLUDED
49 for (
int i = 0; i < 100; ++i) {
55 char *
Write(
int value,
char *to)
const {
56 assert(value >= 0 && value < 100);
57 return std::copy_n(
m_digits[value], 2, to);
75 return writer.
Write(value, to);
87template <
typename T,
int MinDigits,
int MaxDigits,
typename =
void>
89 static_assert(MinDigits < MaxDigits,
"");
90 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
91 "The input should be an unsigned integer.");
94 constexpr int mid = (MinDigits + MaxDigits) / 2;
95 constexpr T pivot =
pow10(mid);
105 for (
int i = 0; i <
n; ++i) x *= 10;
114template <
typename T,
int MinDigits,
int MaxDigits>
116 typename
std::enable_if<MinDigits == MaxDigits>
::type> {
153 *--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:46
constexpr TwoDigitWriter()
Definition: integer_digits.h:48
char m_digits[100][2]
Definition: integer_digits.h:61
char * Write(int value, char *to) const
Definition: integer_digits.h:55
constexpr int count_digits(T x)
Counts the number of base 10 digits in an unsigned integer.
Definition: integer_digits.h:127
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:73
char * write_digits(T number, int digits, char *to)
Writes an unsigned integer of the specified length to a string.
Definition: integer_digits.h:142
Definition: gcs_xcom_synode.h:64
required string type
Definition: replication_group_member_actions.proto:34
static const char digits[]
Definition: stacktrace.cc:598
constexpr int operator()(T) const
Definition: integer_digits.h:117
Functor that calculates the number of digits in an unsigned integer using binary search.
Definition: integer_digits.h:88
constexpr int operator()(T x) const
Definition: integer_digits.h:93
static constexpr T pow10(int n)
Definition: integer_digits.h:103
int n
Definition: xcom_base.cc:509