std::basic_string_view<CharT,Traits>::find_last_of

出自cppreference.com
 
 
 
 
constexpr size_type
    find_last_of( basic_string_view v, size_type pos = npos ) const noexcept;
(1) (C++17 起)
constexpr size_type
    find_last_of( CharT ch, size_type pos = npos ) const noexcept;
(2) (C++17 起)
constexpr size_type
    find_last_of( const CharT* s, size_type pos, size_type count ) const;
(3) (C++17 起)
constexpr size_type
    find_last_of( const CharT* s, size_type pos = npos ) const;
(4) (C++17 起)

尋找最後一個給定字符序列中字符之一相等的字符。不指定準確的搜索算法。搜索只考慮區間 [0pos]。��區間中不存在字符,則將返回 npos

1) 尋找此視圖中 v 的任意字符的最後一次出現,到位置 pos 結束。
2) 等價於 find_last_of(basic_string_view(std::addressof(c), 1), pos)
3) 等價於 find_last_of(basic_string_view(s, count), pos)
4) 等價於 find_last_of(basic_string_view(s), pos)

參數

v - 要搜索的視圖
pos - 要開始搜索的位置
count - 要搜索的字符串的長度
s - 指向要搜索的字符串的指針
ch - 要搜索的字符

返回值

子串的任意字符的最後一次出現位置,或者若找不到這些字符則為 npos

複雜度

最壞情況為 O(size() * v.size())。

示例

#include <string_view>

using namespace std::literals;
constexpr auto N = std::string_view::npos;

static_assert(
    5 == "delete"sv.find_last_of("cdef"sv) &&
      //       └────────────────────┘
    N == "double"sv.find_last_of("fghi"sv) &&
      //
    0 == "else"sv.find_last_of("bcde"sv, 2 /* pos [0..2]: "els" */) &&
      //  └────────────────────────┘
    N == "explicit"sv.find_last_of("abcd"sv, 4 /* pos [0..4]: "expli" */) &&
      //
    3 == "extern"sv.find_last_of('e') &&
      //     └────────────────────┘
    N == "false"sv.find_last_of('x') &&
      //
    0 == "inline"sv.find_last_of('i', 2 /* pos [0..2]: "inl" */) &&
      //  └───────────────────────┘
    N == "mutable"sv.find_last_of('a', 2 /* pos [0..2]: "mut" */) &&
      //
    3 == "namespace"sv.find_last_of("cdef", 3 /* pos [0..3]: "name" */, 3 /* "cde" */) &&
      //     └─────────────────────────┘
    N == "namespace"sv.find_last_of("cdef", 3 /* pos [0..3]: "name" */, 2 /* "cd" */)
);

int main() {}

參閱

在視圖中查找字符
(公開成員函數) [編輯]
尋找子串的最後一次出現
(公開成員函數) [編輯]
查找字符的首次出現
(公開成員函數) [編輯]
查找字符的首次不出現
(公開成員函數) [編輯]
查找字符的最後一次不出現
(公開成員函數) [編輯]
尋找字符的最後一次出現
(std::basic_string<CharT,Traits,Allocator> 的公開成員函數) [編輯]