1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string> 11 12 // constexpr size_type find_first_of(charT c, size_type pos = 0) const; 13 14 #include <string_view> 15 #include <cassert> 16 17 #include "test_macros.h" 18 #include "constexpr_char_traits.hpp" 19 20 template <class S> 21 void 22 test(const S& s, typename S::value_type c, typename S::size_type pos, 23 typename S::size_type x) 24 { 25 assert(s.find_first_of(c, pos) == x); 26 if (x != S::npos) 27 assert(pos <= x && x < s.size()); 28 } 29 30 template <class S> 31 void 32 test(const S& s, typename S::value_type c, typename S::size_type x) 33 { 34 assert(s.find_first_of(c) == x); 35 if (x != S::npos) 36 assert(x < s.size()); 37 } 38 39 int main() 40 { 41 { 42 typedef std::string_view S; 43 test(S(""), 'e', 0, S::npos); 44 test(S(""), 'e', 1, S::npos); 45 test(S("kitcj"), 'e', 0, S::npos); 46 test(S("qkamf"), 'e', 1, S::npos); 47 test(S("nhmko"), 'e', 2, S::npos); 48 test(S("tpsaf"), 'e', 4, S::npos); 49 test(S("lahfb"), 'e', 5, S::npos); 50 test(S("irkhs"), 'e', 6, S::npos); 51 test(S("gmfhdaipsr"), 'e', 0, S::npos); 52 test(S("kantesmpgj"), 'e', 1, 4); 53 test(S("odaftiegpm"), 'e', 5, 6); 54 test(S("oknlrstdpi"), 'e', 9, S::npos); 55 test(S("eolhfgpjqk"), 'e', 10, S::npos); 56 test(S("pcdrofikas"), 'e', 11, S::npos); 57 test(S("nbatdlmekrgcfqsophij"), 'e', 0, 7); 58 test(S("bnrpehidofmqtcksjgla"), 'e', 1, 4); 59 test(S("jdmciepkaqgotsrfnhlb"), 'e', 10, S::npos); 60 test(S("jtdaefblsokrmhpgcnqi"), 'e', 19, S::npos); 61 test(S("hkbgspofltajcnedqmri"), 'e', 20, S::npos); 62 test(S("oselktgbcapndfjihrmq"), 'e', 21, S::npos); 63 64 test(S(""), 'e', S::npos); 65 test(S("csope"), 'e', 4); 66 test(S("gfsmthlkon"), 'e', S::npos); 67 test(S("laenfsbridchgotmkqpj"), 'e', 2); 68 } 69 70 #if TEST_STD_VER > 11 71 { 72 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV; 73 constexpr SV sv1; 74 constexpr SV sv2 { "abcde", 5 }; 75 76 static_assert (sv1.find_first_of( 'e', 0 ) == SV::npos, "" ); 77 static_assert (sv1.find_first_of( 'e', 1 ) == SV::npos, "" ); 78 static_assert (sv2.find_first_of( 'q', 0 ) == SV::npos, "" ); 79 static_assert (sv2.find_first_of( 'e', 1 ) == 4, "" ); 80 static_assert (sv2.find_first_of( 'e', 5 ) == SV::npos, "" ); 81 } 82 #endif 83 } 84