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 // size_type find_first_not_of(charT c, size_type pos = 0) const; // constexpr since C++20
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18
19 template <class S>
20 TEST_CONSTEXPR_CXX20 void
test(const S & s,typename S::value_type c,typename S::size_type pos,typename S::size_type x)21 test(const S& s, typename S::value_type c, typename S::size_type pos,
22 typename S::size_type x)
23 {
24 LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(c, pos));
25 assert(s.find_first_not_of(c, pos) == x);
26 if (x != S::npos)
27 assert(pos <= x && x < s.size());
28 }
29
30 template <class S>
31 TEST_CONSTEXPR_CXX20 void
test(const S & s,typename S::value_type c,typename S::size_type x)32 test(const S& s, typename S::value_type c, typename S::size_type x)
33 {
34 LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(c));
35 assert(s.find_first_not_of(c) == x);
36 if (x != S::npos)
37 assert(x < s.size());
38 }
39
test()40 TEST_CONSTEXPR_CXX20 bool test() {
41 {
42 typedef std::string S;
43 test(S(""), 'q', 0, S::npos);
44 test(S(""), 'q', 1, S::npos);
45 test(S("kitcj"), 'q', 0, 0);
46 test(S("qkamf"), 'q', 1, 1);
47 test(S("nhmko"), 'q', 2, 2);
48 test(S("tpsaf"), 'q', 4, 4);
49 test(S("lahfb"), 'q', 5, S::npos);
50 test(S("irkhs"), 'q', 6, S::npos);
51 test(S("gmfhdaipsr"), 'q', 0, 0);
52 test(S("kantesmpgj"), 'q', 1, 1);
53 test(S("odaftiegpm"), 'q', 5, 5);
54 test(S("oknlrstdpi"), 'q', 9, 9);
55 test(S("eolhfgpjqk"), 'q', 10, S::npos);
56 test(S("pcdrofikas"), 'q', 11, S::npos);
57 test(S("nbatdlmekrgcfqsophij"), 'q', 0, 0);
58 test(S("bnrpehidofmqtcksjgla"), 'q', 1, 1);
59 test(S("jdmciepkaqgotsrfnhlb"), 'q', 10, 10);
60 test(S("jtdaefblsokrmhpgcnqi"), 'q', 19, 19);
61 test(S("hkbgspofltajcnedqmri"), 'q', 20, S::npos);
62 test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
63
64 test(S(""), 'q', S::npos);
65 test(S("q"), 'q', S::npos);
66 test(S("qqq"), 'q', S::npos);
67 test(S("csope"), 'q', 0);
68 test(S("gfsmthlkon"), 'q', 0);
69 test(S("laenfsbridchgotmkqpj"), 'q', 0);
70 }
71 #if TEST_STD_VER >= 11
72 {
73 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
74 test(S(""), 'q', 0, S::npos);
75 test(S(""), 'q', 1, S::npos);
76 test(S("kitcj"), 'q', 0, 0);
77 test(S("qkamf"), 'q', 1, 1);
78 test(S("nhmko"), 'q', 2, 2);
79 test(S("tpsaf"), 'q', 4, 4);
80 test(S("lahfb"), 'q', 5, S::npos);
81 test(S("irkhs"), 'q', 6, S::npos);
82 test(S("gmfhdaipsr"), 'q', 0, 0);
83 test(S("kantesmpgj"), 'q', 1, 1);
84 test(S("odaftiegpm"), 'q', 5, 5);
85 test(S("oknlrstdpi"), 'q', 9, 9);
86 test(S("eolhfgpjqk"), 'q', 10, S::npos);
87 test(S("pcdrofikas"), 'q', 11, S::npos);
88 test(S("nbatdlmekrgcfqsophij"), 'q', 0, 0);
89 test(S("bnrpehidofmqtcksjgla"), 'q', 1, 1);
90 test(S("jdmciepkaqgotsrfnhlb"), 'q', 10, 10);
91 test(S("jtdaefblsokrmhpgcnqi"), 'q', 19, 19);
92 test(S("hkbgspofltajcnedqmri"), 'q', 20, S::npos);
93 test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
94
95 test(S(""), 'q', S::npos);
96 test(S("q"), 'q', S::npos);
97 test(S("qqq"), 'q', S::npos);
98 test(S("csope"), 'q', 0);
99 test(S("gfsmthlkon"), 'q', 0);
100 test(S("laenfsbridchgotmkqpj"), 'q', 0);
101 }
102 #endif
103
104 return true;
105 }
106
main(int,char **)107 int main(int, char**)
108 {
109 test();
110 #if TEST_STD_VER > 17
111 static_assert(test());
112 #endif
113
114 return 0;
115 }
116