• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<wchar_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<wchar_t>::compare(L"123", L"223", 3) < 0
26         && std::char_traits<wchar_t>::compare(L"223", L"123", 3) > 0
27         && std::char_traits<wchar_t>::compare(L"123", L"123", 3) == 0;
28 }
29 #endif
30 
main()31 int main()
32 {
33     assert(std::char_traits<wchar_t>::compare(L"", L"", 0) == 0);
34     assert(std::char_traits<wchar_t>::compare(NULL, NULL, 0) == 0);
35 
36     assert(std::char_traits<wchar_t>::compare(L"1", L"1", 1) == 0);
37     assert(std::char_traits<wchar_t>::compare(L"1", L"2", 1) < 0);
38     assert(std::char_traits<wchar_t>::compare(L"2", L"1", 1) > 0);
39 
40     assert(std::char_traits<wchar_t>::compare(L"12", L"12", 2) == 0);
41     assert(std::char_traits<wchar_t>::compare(L"12", L"13", 2) < 0);
42     assert(std::char_traits<wchar_t>::compare(L"12", L"22", 2) < 0);
43     assert(std::char_traits<wchar_t>::compare(L"13", L"12", 2) > 0);
44     assert(std::char_traits<wchar_t>::compare(L"22", L"12", 2) > 0);
45 
46     assert(std::char_traits<wchar_t>::compare(L"123", L"123", 3) == 0);
47     assert(std::char_traits<wchar_t>::compare(L"123", L"223", 3) < 0);
48     assert(std::char_traits<wchar_t>::compare(L"123", L"133", 3) < 0);
49     assert(std::char_traits<wchar_t>::compare(L"123", L"124", 3) < 0);
50     assert(std::char_traits<wchar_t>::compare(L"223", L"123", 3) > 0);
51     assert(std::char_traits<wchar_t>::compare(L"133", L"123", 3) > 0);
52     assert(std::char_traits<wchar_t>::compare(L"124", L"123", 3) > 0);
53 
54 #if TEST_STD_VER > 14
55     static_assert(test_constexpr(), "" );
56 #endif
57 }
58