xref: /llvm-project/libcxx/test/std/strings/basic.string/string.contains/contains.char.pass.cpp (revision 6e1dcc9335116f650d68cdbed12bbb34a99b2d9b)
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, c++20
9 
10 // <string>
11 
12 // constexpr bool contains(charT x) const noexcept;
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 template <class S>
test_string()20 constexpr void test_string() {
21   S s1{};
22   S s2{"abcde", 5};
23 
24   ASSERT_NOEXCEPT(s1.contains('e'));
25 
26   assert(!s1.contains('c'));
27   assert(!s1.contains('e'));
28   assert(!s1.contains('x'));
29   assert(s2.contains('c'));
30   assert(s2.contains('e'));
31   assert(!s2.contains('x'));
32 }
33 
test()34 constexpr bool test() {
35   test_string<std::string>();
36 
37   return true;
38 }
39 
main(int,char **)40 int main(int, char**) {
41   test();
42   static_assert(test());
43 
44   return 0;
45 }
46