名前空間
変種
操作

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

From 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) このビュー内で、指定された `pos` 位置で終わる、`v` のいずれかの文字の最後の出現箇所を検索します。
2) find_last_of(basic_string_view(std::addressof(ch), 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 - 検索対象の文字文字列へのポインタ
文字 - 検索する文字

[編集] 戻り値

部分文字列のいずれかの文字の最後の出現位置。そのような文字が見つからなかった場合は 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() {}

[編集] 関連項目

ビュー内の文字を検索する
(public member function) [編集]
部分文字列が最後に現れる位置を見つける
(public member function) [編集]
文字が最初に現れる位置を見つける
(public member function) [編集]
文字が最初に現れない位置を見つける
(public member function) [編集]
文字が最後に現れない位置を見つける
(public member function) [編集]
文字が最後に現れる位置を見つける
(std::basic_string<CharT,Traits,Allocator> の public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)