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<char32_t>
12
13// static const char_type* find(const char_type* s, size_t n, const char_type& a);
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
22constexpr bool test_constexpr() {
23 constexpr const char32_t* p = U"123";
24 return std::char_traits<char32_t>::find(p, 3, U'1') == p && std::char_traits<char32_t>::find(p, 3, U'2') == p + 1 &&
25 std::char_traits<char32_t>::find(p, 3, U'3') == p + 2 &&
26 std::char_traits<char32_t>::find(p, 3, U'4') == nullptr;
27}
28#endif
29
30int main(int, char**) {
31 char32_t s1[] = {1, 2, 3};
32 assert(std::char_traits<char32_t>::find(s1, 3, char32_t(1)) == s1);
33 assert(std::char_traits<char32_t>::find(s1, 3, char32_t(2)) == s1 + 1);
34 assert(std::char_traits<char32_t>::find(s1, 3, char32_t(3)) == s1 + 2);
35 assert(std::char_traits<char32_t>::find(s1, 3, char32_t(4)) == 0);
36 assert(std::char_traits<char32_t>::find(s1, 3, char32_t(0)) == 0);
37 assert(std::char_traits<char32_t>::find(NULL, 0, char32_t(0)) == 0);
38
39#if TEST_STD_VER > 14
40 static_assert(test_constexpr(), "");
41#endif
42
43 return 0;
44}
45

source code of libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp