|
22 | 22 | * SOFTWARE. |
23 | 23 | */ |
24 | 24 |
|
| 25 | +#if defined(_WIN32) |
| 26 | +#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING |
| 27 | +#endif |
| 28 | + |
25 | 29 | #include <ww898/utf_converters.hpp> |
26 | 30 |
|
27 | 31 | #if defined(_WIN32) |
|
46 | 50 | #if defined(__linux__) || defined(__APPLE__) |
47 | 51 | #include <chrono> |
48 | 52 |
|
49 | | -#ifdef __MACH__ |
| 53 | +#if defined(__MACH__) |
50 | 54 | #include <mach/clock.h> |
51 | 55 | #include <mach/mach.h> |
52 | 56 | #endif |
@@ -385,10 +389,12 @@ template< |
385 | 389 | typename Ch> |
386 | 390 | struct utf_namer {}; |
387 | 391 |
|
388 | | -template<> struct utf_namer<char > { static char const value[]; }; |
389 | | -template<> struct utf_namer<char16_t> { static char const value[]; }; |
390 | | -template<> struct utf_namer<char32_t> { static char const value[]; }; |
391 | | -template<> struct utf_namer<wchar_t > { static char const value[]; }; |
| 392 | +template<> struct utf_namer< char> { static char const value[]; }; |
| 393 | +template<> struct utf_namer<unsigned char> : utf_namer<char> {}; |
| 394 | +template<> struct utf_namer<signed char> : utf_namer<char> {}; |
| 395 | +template<> struct utf_namer<char16_t > { static char const value[]; }; |
| 396 | +template<> struct utf_namer<char32_t > { static char const value[]; }; |
| 397 | +template<> struct utf_namer<wchar_t > { static char const value[]; }; |
392 | 398 |
|
393 | 399 | char const utf_namer<char >::value[] = "UTF8"; |
394 | 400 | char const utf_namer<char16_t>::value[] = "UTF16"; |
@@ -516,6 +522,57 @@ BOOST_STATIC_ASSERT( utf::is_utf_same<wchar_t, char32_t>::value); |
516 | 522 | #error Unknown platform |
517 | 523 | #endif |
518 | 524 |
|
| 525 | +#if __cpp_constexpr >= 201603 |
| 526 | + |
| 527 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<unsigned char, char>); |
| 528 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<unsigned char, unsigned char>); |
| 529 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<unsigned char, signed char>); |
| 530 | + |
| 531 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<signed char, char>); |
| 532 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<signed char, unsigned char>); |
| 533 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<signed char, signed char>); |
| 534 | + |
| 535 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<char, char>); |
| 536 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<char, unsigned char>); |
| 537 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<char, signed char>); |
| 538 | + |
| 539 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<char16_t, char16_t>); |
| 540 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<char32_t, char32_t>); |
| 541 | +BOOST_STATIC_ASSERT(utf::is_utf_same_v<wchar_t , wchar_t >); |
| 542 | + |
| 543 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char, char16_t>); |
| 544 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char, char32_t>); |
| 545 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char, wchar_t >); |
| 546 | + |
| 547 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char16_t, char>); |
| 548 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char32_t, char>); |
| 549 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<wchar_t , char>); |
| 550 | + |
| 551 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char16_t, char32_t>); |
| 552 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char32_t, char16_t>); |
| 553 | + |
| 554 | +#if defined(_WIN32) |
| 555 | + |
| 556 | +BOOST_STATIC_ASSERT( utf::is_utf_same_v<char16_t, wchar_t>); |
| 557 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char32_t, wchar_t>); |
| 558 | + |
| 559 | +BOOST_STATIC_ASSERT( utf::is_utf_same_v<wchar_t, char16_t>); |
| 560 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<wchar_t, char32_t>); |
| 561 | + |
| 562 | +#elif defined(__linux__) || defined(__APPLE__) |
| 563 | + |
| 564 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<char16_t, wchar_t>); |
| 565 | +BOOST_STATIC_ASSERT( utf::is_utf_same_v<char32_t, wchar_t>); |
| 566 | + |
| 567 | +BOOST_STATIC_ASSERT(!utf::is_utf_same_v<wchar_t, char16_t>); |
| 568 | +BOOST_STATIC_ASSERT( utf::is_utf_same_v<wchar_t, char32_t>); |
| 569 | + |
| 570 | +#else |
| 571 | + #error Unknown platform |
| 572 | +#endif |
| 573 | + |
| 574 | +#endif |
| 575 | + |
519 | 576 | namespace { |
520 | 577 |
|
521 | 578 | uint64_t get_time() throw() |
@@ -560,7 +617,7 @@ uint64_t get_time() throw() |
560 | 617 | #if defined(__linux__) || defined(__APPLE__) |
561 | 618 | void current_utc_time(timespec * ts) |
562 | 619 | { |
563 | | -#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time |
| 620 | +#if defined(__MACH__) // OS X does not have clock_gettime, use clock_get_time |
564 | 621 | clock_serv_t cclock; |
565 | 622 | mach_timespec_t mts; |
566 | 623 | if (host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock) != KERN_SUCCESS) |
@@ -727,6 +784,8 @@ BOOST_AUTO_TEST_CASE(performance, WW898_PERFORMANCE_TESTS_MODE) |
727 | 784 | } |
728 | 785 |
|
729 | 786 | std::cout << |
| 787 | + "__cpp_lib_string_view: " << std::dec << __cpp_lib_string_view << std::endl << |
| 788 | + "__cpp_constexpr : " << std::dec << __cpp_constexpr << std::endl << |
730 | 789 | "sizeof wchar_t: " << sizeof(wchar_t) << std::endl << |
731 | 790 | utf_namer<wchar_t >::value << ": UTF" << 8 * sizeof(wchar_t) << std::endl; |
732 | 791 |
|
@@ -853,10 +912,24 @@ BOOST_AUTO_TEST_CASE(example, WW898_PERFORMANCE_TESTS_MODE) |
853 | 912 | convz<utf32, utf8>(u32.data(), std::back_inserter(u8)); |
854 | 913 | std::wstring uw; |
855 | 914 | conv<utf8, utfw>(u8s, u8s + sizeof(u8s), std::back_inserter(uw)); |
| 915 | + auto u8r = conv<char>(uw); |
| 916 | + auto uwr = convz<wchar_t>(u8s); |
| 917 | + |
| 918 | +#if __cpp_lib_string_view >= 201606 |
| 919 | + auto u32r = conv<char32_t>(std::string_view(u8r.data(), u8r.size())); // C++17 only |
| 920 | +#endif |
| 921 | + |
856 | 922 | static_assert(is_utf_same<decltype(*u8s), decltype(u8)::value_type>::value, "Fail"); |
857 | | - static_assert(1 == |
858 | | - (is_utf_same<decltype(u16)::value_type, decltype(uw)::value_type>::value ? 1 : 0) + |
859 | | - (is_utf_same<decltype(u32)::value_type, decltype(uw)::value_type>::value ? 1 : 0), "Fail"); |
| 923 | + static_assert( |
| 924 | + is_utf_same<decltype(u16)::value_type, decltype(uw)::value_type>::value != |
| 925 | + is_utf_same<decltype(u32)::value_type, decltype(uw)::value_type>::value, "Fail"); |
| 926 | + |
| 927 | +#if __cpp_constexpr >= 201603 |
| 928 | + static_assert(is_utf_same_v<decltype(*u8s), decltype(u8)::value_type>, "Fail"); // C++17 only |
| 929 | + static_assert( |
| 930 | + is_utf_same_v<decltype(u16)::value_type, decltype(uw)::value_type> != |
| 931 | + is_utf_same_v<decltype(u32)::value_type, decltype(uw)::value_type>, "Fail"); // C++17 only |
| 932 | +#endif |
860 | 933 | } |
861 | 934 |
|
862 | 935 | #undef WW898_PERFORMANCE_TESTS_MODE |
|
0 commit comments