std::basic_string_view<CharT,Traits>::rfind
From cppreference.com
< cpp | string | basic string view
| constexpr size_type rfind( basic_string_view v, size_type pos = npos ) const noexcept; |
(1) | (C++17以降) |
| constexpr size_type rfind( CharT ch, size_type pos = npos ) const noexcept; |
(2) | (C++17以降) |
| constexpr size_type rfind( const CharT* s, size_type pos, size_type count ) const; |
(3) | (C++17以降) |
| constexpr size_type rfind( const CharT* s, size_type pos = npos ) const; |
(4) | (C++17以降) |
与えられた文字シーケンスと等しい最後の部分文字列を検索します。検索は pos から開始され、右から左へ進行します(したがって、見つかった部分文字列は、もしあれば、pos より後ろの位置から始まることはありません)。pos として npos または size() - 1 より小さくない値が渡された場合、文字列全体が検索されます。
1) このビュー内で、位置 pos から開始して、v の最後の出現箇所を検索します。
2) rfind(basic_string_view(std::addressof(ch), 1), pos) と同等です。
3) rfind(basic_string_view(s, count), pos) と同等です。
4) rfind(basic_string_view(s), pos) と同等です。
目次 |
[編集] パラメータ
| v | - | 検索対象のビュー |
| pos | - | 検索を開始する位置 |
| count | - | 検索する部分文字列の長さ |
| s | - | 検索するC文字列へのポインタ |
| 文字 | - | 検索する文字 |
[編集] 戻り値
見つかった部分文字列の最初の文字の位置、またはそのような部分文字列が見つからなかった場合は npos。
[編集] 計算量
[編集] 例
このコードを実行
#include <string_view> int main() { using namespace std::literals; constexpr auto N = std::string_view::npos; static_assert(true && (6 == "AB AB AB"sv.rfind("AB")) && (6 == "AB AB AB"sv.rfind("ABCD", N, 2)) && (3 == "AB AB AB"sv.rfind("AB", 5)) && (0 == "AB CD EF"sv.rfind("AB", 0)) && (2 == "B AB AB "sv.rfind("AB", 2)) && (N == "B AB AB "sv.rfind("AB", 1)) && (5 == "B AB AB "sv.rfind('A')) && (4 == "AB AB AB"sv.rfind('B', 4)) && (N == "AB AB AB"sv.rfind('C')) ); }
[編集] 関連項目
| ビュー内の文字を検索する (public member function) | |
| 文字が最初に現れる位置を見つける (public member function) | |
| 文字が最後に現れる位置を見つける (public member function) | |
| 文字が最初に現れない位置を見つける (public member function) | |
| 文字が最後に現れない位置を見つける (public member function) | |
| 部分文字列が最後に現れる位置を見つける ( std::basic_string<CharT,Traits,Allocator> の public メンバ関数) |