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