std:: ptr_fun
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<functional>
|
||
|
template
<
class
Arg,
class
Result
>
std::
pointer_to_unary_function
<
Arg,Result
>
|
(1) |
(C++11부터 사용 중단됨)
(C++17에서 제거됨) |
|
template
<
class
Arg1,
class
Arg2,
class
Result
>
std::
pointer_to_binary_function
<
Arg1,Arg2,Result
>
|
(2) |
(C++11부터 사용 중단됨)
(C++17에서 제거됨) |
함수 래퍼 객체를 생성합니다 ( std:: pointer_to_unary_function 또는 std:: pointer_to_binary_function ). 템플릿 인자로부터 대상 타입을 추론합니다.
이 함수와 관련된 타입들은 C++11부터 더 일반적인 std::function 과 std::ref 를 위해 사용 중단되었으며, 둘 다 일반 함수로부터 호출 가능 어댑터-호환 함수 객체를 생성합니다.
목차 |
매개변수
| f | - | 래퍼를 생성할 함수에 대한 포인터 |
반환값
f 를 감싸는 함수 객체.
예외
구현 정의 예외를 던질 수 있습니다.
예제
#include <algorithm> #include <functional> #include <iostream> #include <string_view> constexpr bool is_vowel(char c) { return std::string_view{"aeoiuAEIOU"}.find(c) != std::string_view::npos; } int main() { std::string_view s = "Hello, world!"; std::ranges::copy_if(s, std::ostreambuf_iterator<char>(std::cout), std::not1(std::ptr_fun(is_vowel))); #if 0 // C++11 alternatives: std::not1(std::cref(is_vowel))); std::not1(std::function<bool(char)>(is_vowel))); [](char c) { return !is_vowel(c); }); // C++17 alternatives: std::not_fn(is_vowel)); #endif }
출력:
Hll, wrld!
참고 항목
|
(C++11)
|
복사 생성 가능한 모든 호출 가능 객체의 복사 가능 래퍼
(클래스 템플릿) |
|
(C++23)
|
주어진 호출 시그니처에서 한정자를 지원하는 모든 호출 가능 객체의 이동 전용 래퍼
(클래스 템플릿) |
|
(C++17)
(C++23)
|
주어진 인수로
Callable
객체를 호출
및 반환 타입 지정 가능
(C++23부터)
(함수 템플릿) |
|
(C++17)
|
보유한 함수 객체의 결과의 보수를 반환하는 함수 객체를 생성
(함수 템플릿) |