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<wchar_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// UNSUPPORTED: no-wide-characters
17
18#include <string>
19#include <cassert>
20
21#include "test_macros.h"
22
23#if TEST_STD_VER > 14
24constexpr bool test_constexpr() {
25 constexpr const wchar_t* p = L"123";
26 return std::char_traits<wchar_t>::find(p, 3, L'1') == p && std::char_traits<wchar_t>::find(p, 3, L'2') == p + 1 &&
27 std::char_traits<wchar_t>::find(p, 3, L'3') == p + 2 && std::char_traits<wchar_t>::find(p, 3, L'4') == nullptr;
28}
29#endif
30
31int main(int, char**) {
32 wchar_t s1[] = {1, 2, 3};
33 assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(1)) == s1);
34 assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(2)) == s1 + 1);
35 assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(3)) == s1 + 2);
36 assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(4)) == 0);
37 assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(0)) == 0);
38 assert(std::char_traits<wchar_t>::find(NULL, 0, wchar_t(0)) == 0);
39
40#if TEST_STD_VER > 14
41 static_assert(test_constexpr(), "");
42#endif
43
44 return 0;
45}
46

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