25#ifndef INTEGER_DIGITS_INCLUDED
26#define INTEGER_DIGITS_INCLUDED
50 for (
int i = 0; i < 100; ++i) {
56 char *
Write(
int value,
char *to)
const {
57 assert(value >= 0 && value < 100);
58 return std::copy_n(
m_digits[value], 2, to);
74MY_ATTRIBUTE((visibility(
"default")))
77 return writer.
Write(value, to);
89template <
typename T,
int MinDigits,
int MaxDigits,
typename =
void>
91 static_assert(MinDigits < MaxDigits,
"");
92 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
93 "The input should be an unsigned integer.");
96 constexpr int mid = (MinDigits + MaxDigits) / 2;
97 constexpr T pivot =
pow10(mid);
107 for (
int i = 0; i <
n; ++i) x *= 10;
116template <
typename T,
int MinDigits,
int MaxDigits>
118 typename
std::enable_if<MinDigits == MaxDigits>
::type> {
155 *--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:47
constexpr TwoDigitWriter()
Definition: integer_digits.h:49
char m_digits[100][2]
Definition: integer_digits.h:62
char * Write(int value, char *to) const
Definition: integer_digits.h:56
constexpr int count_digits(T x)
Counts the number of base 10 digits in an unsigned integer.
Definition: integer_digits.h:129
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:75
char * write_digits(T number, int digits, char *to)
Writes an unsigned integer of the specified length to a string.
Definition: integer_digits.h:144
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:119
Functor that calculates the number of digits in an unsigned integer using binary search.
Definition: integer_digits.h:90
constexpr int operator()(T x) const
Definition: integer_digits.h:95
static constexpr T pow10(int n)
Definition: integer_digits.h:105
int n
Definition: xcom_base.cc:508