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<char16_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
test_constexpr()23 constexpr bool test_constexpr()
24 {
25     return std::char_traits<char16_t>::compare(u"123", u"223", 3) < 0
26         && std::char_traits<char16_t>::compare(u"223", u"123", 3) > 0
27         && std::char_traits<char16_t>::compare(u"123", u"123", 3) == 0;
28 }
29 #endif
30 
31 
main()32 int main()
33 {
34 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
35 #if TEST_STD_VER >= 11
36     assert(std::char_traits<char16_t>::compare(u"", u"", 0) == 0);
37     assert(std::char_traits<char16_t>::compare(NULL, NULL, 0) == 0);
38 
39     assert(std::char_traits<char16_t>::compare(u"1", u"1", 1) == 0);
40     assert(std::char_traits<char16_t>::compare(u"1", u"2", 1) < 0);
41     assert(std::char_traits<char16_t>::compare(u"2", u"1", 1) > 0);
42 
43     assert(std::char_traits<char16_t>::compare(u"12", u"12", 2) == 0);
44     assert(std::char_traits<char16_t>::compare(u"12", u"13", 2) < 0);
45     assert(std::char_traits<char16_t>::compare(u"12", u"22", 2) < 0);
46     assert(std::char_traits<char16_t>::compare(u"13", u"12", 2) > 0);
47     assert(std::char_traits<char16_t>::compare(u"22", u"12", 2) > 0);
48 
49     assert(std::char_traits<char16_t>::compare(u"123", u"123", 3) == 0);
50     assert(std::char_traits<char16_t>::compare(u"123", u"223", 3) < 0);
51     assert(std::char_traits<char16_t>::compare(u"123", u"133", 3) < 0);
52     assert(std::char_traits<char16_t>::compare(u"123", u"124", 3) < 0);
53     assert(std::char_traits<char16_t>::compare(u"223", u"123", 3) > 0);
54     assert(std::char_traits<char16_t>::compare(u"133", u"123", 3) > 0);
55     assert(std::char_traits<char16_t>::compare(u"124", u"123", 3) > 0);
56 #endif
57 
58 #if TEST_STD_VER > 14
59     static_assert(test_constexpr(), "" );
60 #endif
61 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
62 }
63