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
19template <class S>
20TEST_CONSTEXPR_CXX20 void
21test(const S& s, typename S::value_type c, typename S::size_type pos, typename S::size_type x) {
22 LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(c, pos));
23 assert(s.find_first_not_of(c, pos) == x);
24 if (x != S::npos)
25 assert(pos <= x && x < s.size());
26}
27
28template <class S>
29TEST_CONSTEXPR_CXX20 void test(const S& s, typename S::value_type c, typename S::size_type x) {
30 LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(c));
31 assert(s.find_first_not_of(c) == x);
32 if (x != S::npos)
33 assert(x < s.size());
34}
35
36template <class S>
37TEST_CONSTEXPR_CXX20 void test_string() {
38 test(S(""), 'q', 0, S::npos);
39 test(S(""), 'q', 1, S::npos);
40 test(S("kitcj"), 'q', 0, 0);
41 test(S("qkamf"), 'q', 1, 1);
42 test(S("nhmko"), 'q', 2, 2);
43 test(S("tpsaf"), 'q', 4, 4);
44 test(S("lahfb"), 'q', 5, S::npos);
45 test(S("irkhs"), 'q', 6, S::npos);
46 test(S("gmfhdaipsr"), 'q', 0, 0);
47 test(S("kantesmpgj"), 'q', 1, 1);
48 test(S("odaftiegpm"), 'q', 5, 5);
49 test(S("oknlrstdpi"), 'q', 9, 9);
50 test(S("eolhfgpjqk"), 'q', 10, S::npos);
51 test(S("pcdrofikas"), 'q', 11, S::npos);
52 test(S("nbatdlmekrgcfqsophij"), 'q', 0, 0);
53 test(S("bnrpehidofmqtcksjgla"), 'q', 1, 1);
54 test(S("jdmciepkaqgotsrfnhlb"), 'q', 10, 10);
55 test(S("jtdaefblsokrmhpgcnqi"), 'q', 19, 19);
56 test(S("hkbgspofltajcnedqmri"), 'q', 20, S::npos);
57 test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
58
59 test(S(""), 'q', S::npos);
60 test(S("q"), 'q', S::npos);
61 test(S("qqq"), 'q', S::npos);
62 test(S("csope"), 'q', 0);
63 test(S("gfsmthlkon"), 'q', 0);
64 test(S("laenfsbridchgotmkqpj"), 'q', 0);
65}
66
67TEST_CONSTEXPR_CXX20 bool test() {
68 test_string<std::string>();
69#if TEST_STD_VER >= 11
70 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
71#endif
72
73 return true;
74}
75
76int main(int, char**) {
77 test();
78#if TEST_STD_VER > 17
79 static_assert(test());
80#endif
81
82 return 0;
83}
84

source code of libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/char_size.pass.cpp