roll back some parts of the change
This commit is contained in:
parent
d585b6e86e
commit
fefa98702c
@ -678,7 +678,7 @@ class serializer
|
|||||||
template <typename NumberType, enable_if_t<std::numeric_limits<NumberType>::is_signed, int> = 0>
|
template <typename NumberType, enable_if_t<std::numeric_limits<NumberType>::is_signed, int> = 0>
|
||||||
bool is_negative_number(NumberType x)
|
bool is_negative_number(NumberType x)
|
||||||
{
|
{
|
||||||
return x < NumberType(0);
|
return x < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename NumberType, enable_if_t < !std::numeric_limits<NumberType>::is_signed, int > = 0 >
|
template < typename NumberType, enable_if_t < !std::numeric_limits<NumberType>::is_signed, int > = 0 >
|
||||||
@ -721,7 +721,7 @@ class serializer
|
|||||||
};
|
};
|
||||||
|
|
||||||
// special case for "0"
|
// special case for "0"
|
||||||
if (x == NumberType(0))
|
if (x == 0)
|
||||||
{
|
{
|
||||||
o->write_character('0');
|
o->write_character('0');
|
||||||
return;
|
return;
|
||||||
@ -757,16 +757,15 @@ class serializer
|
|||||||
|
|
||||||
// Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
|
// Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
|
||||||
// See: https://www.youtube.com/watch?v=o4-CwDo2zpg
|
// See: https://www.youtube.com/watch?v=o4-CwDo2zpg
|
||||||
const NumberType hundred = 100;
|
while (abs_value >= 100)
|
||||||
while (abs_value >= hundred)
|
|
||||||
{
|
{
|
||||||
const auto digits_index = static_cast<unsigned>((abs_value % hundred));
|
const auto digits_index = static_cast<unsigned>((abs_value % 100));
|
||||||
abs_value /= hundred;
|
abs_value /= 100;
|
||||||
*(--buffer_ptr) = digits_to_99[digits_index][1];
|
*(--buffer_ptr) = digits_to_99[digits_index][1];
|
||||||
*(--buffer_ptr) = digits_to_99[digits_index][0];
|
*(--buffer_ptr) = digits_to_99[digits_index][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abs_value >= NumberType(10))
|
if (abs_value >= 10)
|
||||||
{
|
{
|
||||||
const auto digits_index = static_cast<unsigned>(abs_value);
|
const auto digits_index = static_cast<unsigned>(abs_value);
|
||||||
*(--buffer_ptr) = digits_to_99[digits_index][1];
|
*(--buffer_ptr) = digits_to_99[digits_index][1];
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class wrapped_int
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
wrapped_int() = default;
|
wrapped_int() = default;
|
||||||
wrapped_int(T val) : val(val) {}
|
/* implicit */ wrapped_int(T val) : val(val) {}
|
||||||
|
|
||||||
bool operator==(const wrapped_int& other) const
|
bool operator==(const wrapped_int& other) const
|
||||||
{
|
{
|
||||||
@ -59,37 +59,29 @@ class wrapped_int
|
|||||||
}
|
}
|
||||||
bool operator%(const wrapped_int& other) const
|
bool operator%(const wrapped_int& other) const
|
||||||
{
|
{
|
||||||
return static_cast<T>(*this) % static_cast<T>(other.val);
|
return static_cast<T>(*this) % static_cast<T>(other);
|
||||||
}
|
}
|
||||||
wrapped_int& operator/=(const wrapped_int& other)
|
wrapped_int& operator/=(const wrapped_int& other)
|
||||||
{
|
{
|
||||||
if (val != nullptr)
|
val /= static_cast<T>(other);
|
||||||
{
|
|
||||||
*val /= static_cast<T>(other.val);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
bool operator<(const wrapped_int& other) const
|
bool operator<(const wrapped_int& other) const
|
||||||
{
|
{
|
||||||
return static_cast<T>(*this) < static_cast<T>(other.val);
|
return static_cast<T>(*this) < static_cast<T>(other);
|
||||||
}
|
}
|
||||||
bool operator<=(const wrapped_int& other) const
|
bool operator<=(const wrapped_int& other) const
|
||||||
{
|
{
|
||||||
return static_cast<T>(*this) <= static_cast<T>(other.val);
|
return static_cast<T>(*this) <= static_cast<T>(other);
|
||||||
}
|
|
||||||
|
|
||||||
friend void swap(wrapped_int& self, wrapped_int& other)
|
|
||||||
{
|
|
||||||
swap(self.val, other.val);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> class std::numeric_limits<wrapped_int<T>>
|
template<typename T> class std::numeric_limits<wrapped_int<T>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static constexpr bool is_specialized = std::numeric_limits<T>::is_specialized;
|
||||||
static constexpr bool is_signed = std::numeric_limits<T>::is_signed;
|
static constexpr bool is_signed = std::numeric_limits<T>::is_signed;
|
||||||
static constexpr bool is_integer = std::numeric_limits<T>::is_integer;
|
static constexpr bool is_integer = std::numeric_limits<T>::is_integer;
|
||||||
static constexpr bool is_specialized = std::numeric_limits<T>::is_specialized;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("custom integer types")
|
TEST_CASE("custom integer types")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user