1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <string>
10
11 // template<> struct char_traits<char16_t>
12
13 // static int compare(const char_type* s1, const char_type* s2, size_t n);
14 // constexpr in C++17
15
16 #include <string>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 #if TEST_STD_VER > 14
test_constexpr()22 constexpr bool test_constexpr()
23 {
24 return std::char_traits<char16_t>::compare(u"123", u"223", 3) < 0
25 && std::char_traits<char16_t>::compare(u"223", u"123", 3) > 0
26 && std::char_traits<char16_t>::compare(u"123", u"123", 3) == 0;
27 }
28 #endif
29
30
main(int,char **)31 int main(int, char**)
32 {
33 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
34 #if TEST_STD_VER >= 11
35 assert(std::char_traits<char16_t>::compare(u"", u"", 0) == 0);
36 assert(std::char_traits<char16_t>::compare(NULL, NULL, 0) == 0);
37
38 assert(std::char_traits<char16_t>::compare(u"1", u"1", 1) == 0);
39 assert(std::char_traits<char16_t>::compare(u"1", u"2", 1) < 0);
40 assert(std::char_traits<char16_t>::compare(u"2", u"1", 1) > 0);
41
42 assert(std::char_traits<char16_t>::compare(u"12", u"12", 2) == 0);
43 assert(std::char_traits<char16_t>::compare(u"12", u"13", 2) < 0);
44 assert(std::char_traits<char16_t>::compare(u"12", u"22", 2) < 0);
45 assert(std::char_traits<char16_t>::compare(u"13", u"12", 2) > 0);
46 assert(std::char_traits<char16_t>::compare(u"22", u"12", 2) > 0);
47
48 assert(std::char_traits<char16_t>::compare(u"123", u"123", 3) == 0);
49 assert(std::char_traits<char16_t>::compare(u"123", u"223", 3) < 0);
50 assert(std::char_traits<char16_t>::compare(u"123", u"133", 3) < 0);
51 assert(std::char_traits<char16_t>::compare(u"123", u"124", 3) < 0);
52 assert(std::char_traits<char16_t>::compare(u"223", u"123", 3) > 0);
53 assert(std::char_traits<char16_t>::compare(u"133", u"123", 3) > 0);
54 assert(std::char_traits<char16_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 return 0;
63 }
64