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// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10
11// <string_view>
12
13// constexpr size_type find_first_of(charT c, size_type pos = 0) const;
14
15#include <string_view>
16#include <cassert>
17
18#include "test_macros.h"
19#include "constexpr_char_traits.h"
20
21template <class S>
22void test(const S& s, typename S::value_type c, typename S::size_type pos, typename S::size_type x) {
23 LIBCPP_ASSERT_NOEXCEPT(s.find_first_of(c, pos));
24 assert(s.find_first_of(c, pos) == x);
25 if (x != S::npos)
26 assert(pos <= x && x < s.size());
27}
28
29template <class S>
30void test(const S& s, typename S::value_type c, typename S::size_type x) {
31 assert(s.find_first_of(c) == x);
32 if (x != S::npos)
33 assert(x < s.size());
34}
35
36int main(int, char**) {
37 {
38 typedef std::string_view S;
39 test(s: S(""), c: 'e', pos: 0, x: S::npos);
40 test(s: S(""), c: 'e', pos: 1, x: S::npos);
41 test(s: S("kitcj"), c: 'e', pos: 0, x: S::npos);
42 test(s: S("qkamf"), c: 'e', pos: 1, x: S::npos);
43 test(s: S("nhmko"), c: 'e', pos: 2, x: S::npos);
44 test(s: S("tpsaf"), c: 'e', pos: 4, x: S::npos);
45 test(s: S("lahfb"), c: 'e', pos: 5, x: S::npos);
46 test(s: S("irkhs"), c: 'e', pos: 6, x: S::npos);
47 test(s: S("gmfhdaipsr"), c: 'e', pos: 0, x: S::npos);
48 test(s: S("kantesmpgj"), c: 'e', pos: 1, x: 4);
49 test(s: S("odaftiegpm"), c: 'e', pos: 5, x: 6);
50 test(s: S("oknlrstdpi"), c: 'e', pos: 9, x: S::npos);
51 test(s: S("eolhfgpjqk"), c: 'e', pos: 10, x: S::npos);
52 test(s: S("pcdrofikas"), c: 'e', pos: 11, x: S::npos);
53 test(s: S("nbatdlmekrgcfqsophij"), c: 'e', pos: 0, x: 7);
54 test(s: S("bnrpehidofmqtcksjgla"), c: 'e', pos: 1, x: 4);
55 test(s: S("jdmciepkaqgotsrfnhlb"), c: 'e', pos: 10, x: S::npos);
56 test(s: S("jtdaefblsokrmhpgcnqi"), c: 'e', pos: 19, x: S::npos);
57 test(s: S("hkbgspofltajcnedqmri"), c: 'e', pos: 20, x: S::npos);
58 test(s: S("oselktgbcapndfjihrmq"), c: 'e', pos: 21, x: S::npos);
59
60 test(s: S(""), c: 'e', x: S::npos);
61 test(s: S("csope"), c: 'e', x: 4);
62 test(s: S("gfsmthlkon"), c: 'e', x: S::npos);
63 test(s: S("laenfsbridchgotmkqpj"), c: 'e', x: 2);
64 }
65
66#if TEST_STD_VER > 11
67 {
68 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
69 constexpr SV sv1;
70 constexpr SV sv2{"abcde", 5};
71
72 static_assert(sv1.find_first_of('e', 0) == SV::npos, "");
73 static_assert(sv1.find_first_of('e', 1) == SV::npos, "");
74 static_assert(sv2.find_first_of('q', 0) == SV::npos, "");
75 static_assert(sv2.find_first_of('e', 1) == 4, "");
76 static_assert(sv2.find_first_of('e', 5) == SV::npos, "");
77 }
78#endif
79
80 return 0;
81}
82

source code of libcxx/test/std/strings/string.view/string.view.find/find_first_of_char_size.pass.cpp