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