Home | History | Annotate | Download | only in char.traits.specializations.char32_t
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <string>
     11 
     12 // template<> struct char_traits<char32_t>
     13 
     14 // static int compare(const char_type* s1, const char_type* s2, size_t n);
     15 // constexpr in C++17
     16 
     17 #include <string>
     18 #include <cassert>
     19 
     20 #include "test_macros.h"
     21 
     22 #if TEST_STD_VER > 14
     23 constexpr bool test_constexpr()
     24 {
     25     return std::char_traits<char32_t>::compare(U"123", U"223", 3) < 0
     26         && std::char_traits<char32_t>::compare(U"223", U"123", 3) > 0
     27         && std::char_traits<char32_t>::compare(U"123", U"123", 3) == 0;
     28 }
     29 #endif
     30 
     31 int main()
     32 {
     33 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     34 #if TEST_STD_VER >= 11
     35     assert(std::char_traits<char32_t>::compare(U"", U"", 0) == 0);
     36     assert(std::char_traits<char32_t>::compare(NULL, NULL, 0) == 0);
     37 
     38     assert(std::char_traits<char32_t>::compare(U"1", U"1", 1) == 0);
     39     assert(std::char_traits<char32_t>::compare(U"1", U"2", 1) < 0);
     40     assert(std::char_traits<char32_t>::compare(U"2", U"1", 1) > 0);
     41 
     42     assert(std::char_traits<char32_t>::compare(U"12", U"12", 2) == 0);
     43     assert(std::char_traits<char32_t>::compare(U"12", U"13", 2) < 0);
     44     assert(std::char_traits<char32_t>::compare(U"12", U"22", 2) < 0);
     45     assert(std::char_traits<char32_t>::compare(U"13", U"12", 2) > 0);
     46     assert(std::char_traits<char32_t>::compare(U"22", U"12", 2) > 0);
     47 
     48     assert(std::char_traits<char32_t>::compare(U"123", U"123", 3) == 0);
     49     assert(std::char_traits<char32_t>::compare(U"123", U"223", 3) < 0);
     50     assert(std::char_traits<char32_t>::compare(U"123", U"133", 3) < 0);
     51     assert(std::char_traits<char32_t>::compare(U"123", U"124", 3) < 0);
     52     assert(std::char_traits<char32_t>::compare(U"223", U"123", 3) > 0);
     53     assert(std::char_traits<char32_t>::compare(U"133", U"123", 3) > 0);
     54     assert(std::char_traits<char32_t>::compare(U"124", U"123", 3) > 0);
     55 #endif
     56 
     57 #if TEST_STD_VER > 14
     58     static_assert(test_constexpr(), "" );
     59 #endif
     60 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
     61 }
     62