Get bool conversion to work
This commit is contained in:
parent
d5b5b5ed0c
commit
f87cddeeeb
2 changed files with 19 additions and 4 deletions
|
@ -74,7 +74,7 @@ namespace dhandy {
|
|||
static constexpr CastedType cast (I in) { return static_cast<CastedType>(in); }
|
||||
};
|
||||
|
||||
template <typename I, unsigned int Base, typename Tr>
|
||||
template <typename I, unsigned int Base, typename Tr, typename=void>
|
||||
struct IntConversion {
|
||||
static constexpr ReversedSizedArray<std::decay_t<decltype(std::declval<Tr>().to_digit(1))>, implem::int_info<I, Base>::max_len + 1> to_ary (I in) {
|
||||
using RetType = ReversedSizedArray<std::decay_t<decltype(std::declval<Tr>().to_digit(1))>, implem::int_info<I, Base>::max_len + 1>;
|
||||
|
@ -94,8 +94,20 @@ namespace dhandy {
|
|||
}
|
||||
};
|
||||
|
||||
template <unsigned int Base, typename Tr>
|
||||
struct IntConversion<bool, Base, Tr, void> {
|
||||
static constexpr ReversedSizedArray<std::decay_t<decltype(std::declval<Tr>().to_digit(1))>, 2> to_ary (bool in) {
|
||||
using RetType = ReversedSizedArray<std::decay_t<decltype(std::declval<Tr>().to_digit(1))>, 2>;
|
||||
|
||||
RetType arr;
|
||||
arr.push_front('\0');
|
||||
arr.push_front(in ? Tr::to_digit(1) : Tr::to_digit(0));
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename I, typename Tr>
|
||||
struct IntConversion<I, 10, Tr> {
|
||||
struct IntConversion<I, 10, Tr, typename std::enable_if<std::is_integral<I>::value and not std::is_same<I, bool>::value>::type> {
|
||||
static constexpr ReversedSizedArray<std::decay_t<decltype(std::declval<Tr>().to_digit(1))>, implem::int_info<I, 10>::max_len + 1> to_ary (I in) {
|
||||
using RetType = ReversedSizedArray<std::decay_t<decltype(std::declval<Tr>().to_digit(1))>, implem::int_info<I, 10>::max_len + 1>;
|
||||
using Num = implem::NumberAdaptation<I, 10>;
|
||||
|
|
|
@ -81,8 +81,10 @@ TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
|
|||
CHECK(to_string_view(int_to_ary<uint32_t, 16>(0)) == "0");
|
||||
CHECK(to_string_view(int_to_ary<int32_t, 10>(0)) == "0");
|
||||
CHECK(to_string_view(int_to_ary<uint32_t, 10>(0)) == "0");
|
||||
//CHECK(to_string_view(int_to_ary<bool, 8>(false)) == "0");
|
||||
//CHECK(to_string_view(int_to_ary<bool, 8>(true)) == "0");
|
||||
CHECK(to_string_view(int_to_ary<bool, 8>(false)) == "0");
|
||||
CHECK(to_string_view(int_to_ary<bool, 8>(true)) == "1");
|
||||
CHECK(to_string_view(int_to_ary<bool, 10>(false)) == "0");
|
||||
CHECK(to_string_view(int_to_ary<bool, 10>(true)) == "1");
|
||||
CHECK(to_string_view(int_to_ary<uint8_t, 2>(0b10101010)) == "10101010");
|
||||
CHECK(to_string_view(int_to_ary<int8_t, 2>(0b10101010)) == "10101010");
|
||||
CHECK(to_string_view(int_to_ary<uint8_t, 2>(0b11111111)) == "11111111");
|
||||
|
@ -92,6 +94,7 @@ TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
|
|||
CHECK(to_string_view(int_to_ary<int64_t, 36>(9223372036854775807)) == "1y2p0ij32e8e7");
|
||||
CHECK(to_string_view(int_to_ary<int64_t, 36>(0x8000000000000001)) == "1y2p0ij32e8e9");
|
||||
#if defined(__GNUC__)
|
||||
static_assert(std::is_integral<__int128_t>::value, "Warning, int128 won't pickup the optimized base 10 conversion path");
|
||||
__int128_t num = 10000000000000000000U;
|
||||
CHECK(to_string_view(int_to_ary<__int128_t, 10>(num * 100)) == "1000000000000000000000");
|
||||
num = 0xFFFFFFFFFFFFFFFF;
|
||||
|
|
Loading…
Reference in a new issue