std::basic_string<CharT,Traits,Allocator>:: find_first_of
|
size_type find_first_of
(
const
basic_string
&
str, size_type pos
=
0
)
const
;
|
(1) |
(C++11부터 noexcept)
(C++20부터 constexpr) |
|
size_type find_first_of
(
const
CharT
*
s,
size_type pos, size_type count ) const ; |
(2) | (C++20부터 constexpr) |
|
size_type find_first_of
(
const
CharT
*
s, size_type pos
=
0
)
const
;
|
(3) | (C++20부터 constexpr) |
|
size_type find_first_of
(
CharT ch, size_type pos
=
0
)
const
;
|
(4) |
(C++11부터 noexcept)
(C++20부터 constexpr) |
|
template
<
class
StringViewLike
>
size_type
|
(5) |
(C++17부터)
(C++20부터 constexpr) |
주어진 문자 시퀀스에 있는 문자 중 하나와 일치하는 첫 번째 문자를 찾습니다. 검색은
[
pos
,
size()
)
범위 내에서만 수행됩니다. 주어진 문자 시퀀스에 있는 어떤 문자도 해당 범위에 존재하지 않는 경우,
npos
가 반환됩니다.
[
s
,
s
+
count
)
내의 문자들 중 하나와 일치하는 첫 번째 문자를 찾습니다. 이 범위는 null 문자를 포함할 수 있습니다.
[
s
,
s
+
count
)
가 유효한 범위가 아니라면, 동작은 정의되지 않습니다.
std:: basic_string_view < CharT, Traits >> 가 true 이고 std:: is_convertible_v < const StringViewLike & , const CharT * > 가 false 인 경우입니다.
목차 |
매개변수
| str | - | 검색할 문자들을 식별하는 문자열 |
| pos | - | 검색을 시작할 위치 |
| count | - | 검색할 문자들을 식별하는 문자열의 길이 |
| s | - | 검색할 문자들을 식별하는 문자열에 대한 포인터 |
| ch | - | 검색할 문자 |
| t | - | 검색할 문자들을 식별하는 객체 ( std::basic_string_view 로 변환 가능) |
반환값
발견된 문자의 위치 또는 npos 해당 문자가 발견되지 않을 경우.
예외
어떤 이유로든 예외가 발생하면, 이 함수는 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).
참고 사항
Traits :: eq ( ) 비교를 수행하는 데 사용됩니다.
예제
#include <cassert> #include <iostream> #include <string> #include <string_view> int main() { using namespace std::literals; std::string::size_type sz; // (1) sz = "alignas"s.find_first_of("klmn"s); // └────────────────────────┘ assert(sz == 1); sz = "alignof"s.find_first_of("wxyz"s); // 일치하는 항목 없음 assert(sz == std::string::npos); // (2) sz = "consteval"s.find_first_of("xyzabc", 0, 3); // 일치하는 항목 없음 (×는 대상이 아님) ××× assert(sz == std::string::npos); sz = "consteval"s.find_first_of("xyzabc", 0, 6); // └───────────────────────────────┘ assert(sz == 0); // (3) sz = "decltype"s.find_first_of("xyzabc"); // └────────────────────────────┘ assert(sz == 2); // (4) sz = "co_await"s.find_first_of('a'); // └──────────────────────┘ assert(sz == 3); // (5) sz = "constinit"s.find_first_of("int"sv); // └─────────────────────────┘ assert(sz == 2); std::cout << "All tests passed.\n"; }
출력:
All tests passed.
결함 보고서
다음 동작 변경 결함 보고서는 이전에 게시된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 847 | C++98 | 예외 안전성 보장이 없었음 | 강력한 예외 안전성 보장 추가 |
| LWG 2064 | C++11 | 오버로드 (3,4) 가 noexcept였음 | 제거됨 |
| LWG 2946 | C++17 | 오버로드 (5) 가 일부 경우에 모호성 발생 | 템플릿으로 만들어 회피 |
| P1148R0 |
C++11
C++17 |
오버로드
(4,5)
에 대한 noexcept가
LWG2064/LWG2946에 의해 실수로 제거됨 |
복원됨 |
참고 항목
|
주어진 부분 문자열의 첫 번째 발생 위치를 찾음
(public member function) |
|
|
부분 문자열의 마지막 발생 위치를 찾음
(public member function) |
|
|
문자가 처음으로 나타나지 않는 위치를 찾음
(public member function) |
|
|
문자의 마지막 발생 위치를 찾음
(public member function) |
|
|
문자가 마지막으로 나타나지 않는 위치를 찾음
(public member function) |
|
|
문자의 첫 번째 발생 위치를 찾음
(public member function of
std::basic_string_view<CharT,Traits>
)
|
|
|
다른 바이트 문자열에서 발견된 문자들로만 구성된
최대 초기 세그먼트의 길이를 반환 (function) |