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) 이 뷰에서 v 의 문자들 중 하나가 pos 위치에서 끝나는 마지막 발생을 찾습니다.
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 /* 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 member function)