Namespaces
Variants

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

From cppreference.net
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以降)

指定された文字シーケンス内のいずれかの文字に等しい最後の文字を検索します。正確な検索アルゴリズムは指定されていません。検索は区間 [ 0 , pos ] のみを考慮します。指定された区間にその文字が存在しない場合、 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 - 検索対象文字列へのポインタ
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 /* 位置 [0..2]: "els" */) &&
      //  └────────────────────────┘
    N == "explicit"sv.find_last_of("abcd"sv, 4 /* 位置 [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 /* 位置 [0..2]: "inl" */) &&
      //  └───────────────────────┘
    N == "mutable"sv.find_last_of('a', 2 /* 位置 [0..2]: "mut" */) &&
      //
    3 == "namespace"sv.find_last_of("cdef", 3 /* 位置 [0..3]: "name" */, 3 /* "cde" */) &&
      //     └─────────────────────────┘
    N == "namespace"sv.find_last_of("cdef", 3 /* 位置 [0..3]: "name" */, 2 /* "cd" */)
);
int main() {}

関連項目

ビュー内の文字を検索
(公開メンバ関数)
部分文字列の最後の出現を検索
(公開メンバ関数)
文字の最初の出現を検索
(公開メンバ関数)
文字の最初の不在を検索
(公開メンバ関数)
文字の最後の不在を検索
(公開メンバ関数)
文字の最後の出現を検索
( std::basic_string<CharT,Traits,Allocator> の公開メンバ関数)