Delete dangerously incorrect to_string_view helpers.

This commit is contained in:
King_DuckZ 2018-07-29 08:32:30 +01:00
parent beb4d231b2
commit 7c973896d7
2 changed files with 35 additions and 50 deletions

View file

@ -25,9 +25,6 @@
#include <cstddef>
#include <array>
#include <limits>
#if !defined(INT_CONV_WITHOUT_HELPERS)
# include <string_view>
#endif
#include <emmintrin.h>
#if defined(__SSE4_1__)
# include <smmintrin.h>
@ -289,18 +286,6 @@ namespace dhandy {
inline R ary_to_int (C* beg, C* end) {
return implem::AryConversion<R, Base, Tr>::from_ary(beg, end);
}
#if !defined(INT_CONV_WITHOUT_HELPERS)
template <typename T, std::size_t S>
std::basic_string_view<T> to_string_view (const ReversedSizedArray<T, S>& ary) {
return std::basic_string_view<T>(ary.data(), ary.size() - 1);
}
template <typename I, typename C=char>
std::basic_string_view<C> to_string_view (I num) {
return std::basic_string_view<C>(int_to_ary(num));
}
#endif
} //namespace dhandy
#endif

View file

@ -67,46 +67,46 @@ TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
static_assert(int_info_10<int16_t>::is_signed == true, "Wrong sign detection");
static_assert(string<strlen(int_to_ary<int16_t>(0xAB12).data()) + 1>(int_to_ary<int16_t>(0xAB12).data()) == make_string("-21742"), "Algorithm error");
CHECK(to_string_view(int_to_ary<int64_t>(0x123456789A)) == "78187493530");
CHECK(to_string_view(int_to_ary<int64_t>(-1)) == "-1");
CHECK(to_string_view(int_to_ary<int64_t>(0x1000000000000000)) == "1152921504606846976");
CHECK(to_string_view(int_to_ary<int64_t>(0xF000000000000000)) == "-1152921504606846976");
//CHECK(to_string_view(int_to_ary<int64_t>(0x123456789A)) == "78187493530");
//CHECK(to_string_view(int_to_ary<int64_t>(-1)) == "-1");
//CHECK(to_string_view(int_to_ary<int64_t>(0x1000000000000000)) == "1152921504606846976");
//CHECK(to_string_view(int_to_ary<int64_t>(0xF000000000000000)) == "-1152921504606846976");
CHECK(to_string_view(int_to_ary<uint16_t, 16>(0xFFFF)) == "ffff");
CHECK(to_string_view(int_to_ary<uint16_t, 16>(0xCACA)) == "caca");
CHECK(to_string_view(int_to_ary<uint16_t, 16>(0x10)) == "10");
CHECK(to_string_view(int_to_ary<int16_t, 16>(0x10)) == "10");
CHECK(to_string_view(int_to_ary<int16_t, 16>(0xF000)) == "f000");
CHECK(to_string_view(int_to_ary<uint16_t, 16>(0xFEFE)) == "fefe");
CHECK(to_string_view(int_to_ary<int16_t, 16>(0xFEFE)) == "fefe");
CHECK(to_string_view(int_to_ary<uint32_t, 8>(0423)) == "423");
CHECK(to_string_view(int_to_ary<uint32_t, 8>(0777)) == "777");
CHECK(to_string_view(int_to_ary<int32_t, 8>(0)) == "0");
CHECK(to_string_view(int_to_ary<uint32_t, 8>(0)) == "0");
CHECK(to_string_view(int_to_ary<int32_t, 2>(0)) == "0");
CHECK(to_string_view(int_to_ary<uint32_t, 2>(0)) == "0");
CHECK(to_string_view(int_to_ary<int32_t, 16>(0)) == "0");
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)) == "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");
CHECK(to_string_view(int_to_ary<int8_t, 2>(0b11111111)) == "11111111");
CHECK(to_string_view(int_to_ary<uint16_t, 2>(0b111100001111)) == "111100001111");
CHECK(to_string_view(int_to_ary<int16_t, 2>(0b111100001111)) == "111100001111");
CHECK(to_string_view(int_to_ary<int64_t, 36>(9223372036854775807)) == "1y2p0ij32e8e7");
CHECK(to_string_view(int_to_ary<int64_t, 36>(0x8000000000000001)) == "1y2p0ij32e8e9");
//CHECK(to_string_view(int_to_ary<uint16_t, 16>(0xFFFF)) == "ffff");
//CHECK(to_string_view(int_to_ary<uint16_t, 16>(0xCACA)) == "caca");
//CHECK(to_string_view(int_to_ary<uint16_t, 16>(0x10)) == "10");
//CHECK(to_string_view(int_to_ary<int16_t, 16>(0x10)) == "10");
//CHECK(to_string_view(int_to_ary<int16_t, 16>(0xF000)) == "f000");
//CHECK(to_string_view(int_to_ary<uint16_t, 16>(0xFEFE)) == "fefe");
//CHECK(to_string_view(int_to_ary<int16_t, 16>(0xFEFE)) == "fefe");
//CHECK(to_string_view(int_to_ary<uint32_t, 8>(0423)) == "423");
//CHECK(to_string_view(int_to_ary<uint32_t, 8>(0777)) == "777");
//CHECK(to_string_view(int_to_ary<int32_t, 8>(0)) == "0");
//CHECK(to_string_view(int_to_ary<uint32_t, 8>(0)) == "0");
//CHECK(to_string_view(int_to_ary<int32_t, 2>(0)) == "0");
//CHECK(to_string_view(int_to_ary<uint32_t, 2>(0)) == "0");
//CHECK(to_string_view(int_to_ary<int32_t, 16>(0)) == "0");
//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)) == "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");
//CHECK(to_string_view(int_to_ary<int8_t, 2>(0b11111111)) == "11111111");
//CHECK(to_string_view(int_to_ary<uint16_t, 2>(0b111100001111)) == "111100001111");
//CHECK(to_string_view(int_to_ary<int16_t, 2>(0b111100001111)) == "111100001111");
//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");
//CHECK(to_string_view(int_to_ary<__int128_t, 10>(num * 100)) == "1000000000000000000000");
num = 0xFFFFFFFFFFFFFFFF;
CHECK(to_string_view(int_to_ary<__int128_t, 16>(num * 0x10000 + 0xffff)) == "ffffffffffffffffffff");
//CHECK(to_string_view(int_to_ary<__int128_t, 16>(num * 0x10000 + 0xffff)) == "ffffffffffffffffffff");
#endif
}