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 // UNSUPPORTED: c++03, c++11, c++14, c++17
9
10 // <string>
11
12 // template<> struct char_traits<char8_t>
13
14 // static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a);
15
16 #include <string>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
test_constexpr()22 constexpr bool test_constexpr()
23 {
24 constexpr const char8_t *p = u8"123";
25 return std::char_traits<char8_t>::find(p, 3, u8'1') == p
26 && std::char_traits<char8_t>::find(p, 3, u8'2') == p + 1
27 && std::char_traits<char8_t>::find(p, 3, u8'3') == p + 2
28 && std::char_traits<char8_t>::find(p, 3, u8'4') == nullptr;
29 }
30
main(int,char **)31 int main(int, char**)
32 {
33 char8_t s1[] = {1, 2, 3};
34 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(1)) == s1);
35 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(2)) == s1+1);
36 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(3)) == s1+2);
37 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(4)) == 0);
38 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(0)) == 0);
39 assert(std::char_traits<char8_t>::find(NULL, 0, char8_t(0)) == 0);
40
41 static_assert(test_constexpr(), "" );
42 return 0;
43 }
44 #else
main(int,char **)45 int main(int, char**) {
46 return 0;
47 }
48 #endif
49