std::ptr_fun
ko.cppreference.net
| 헤더 <functional>
|
||
template< class Arg, class Result >
std::pointer_to_unary_function<Arg,Result>
ptr_fun( Result (*f)(Arg) );
|
에 정의됨 (1) | (C++11에서 폐지됨) (C++17에서 제거됨) |
template< class Arg1, class Arg2, class Result >
std::pointer_to_binary_function<Arg1,Arg2,Result>
ptr_fun( Result (*f)(Arg1, Arg2) );
|
(2) | (C++11에서 폐지됨) (C++17에서 제거됨) |
템플릿 인자에서 대상 타입을 추론하여 함수 래퍼 객체(std::pointer_to_unary_function 또는 std::pointer_to_binary_function)를 생성합니다.
1) 효과적으로
std::pointer_to_unary_function<Arg,Result>(f)을(를) 호출합니다.2) 효과적으로
std::pointer_to_binary_function<Arg1,Arg2,Result>(f)을(를) 호출합니다.이 함수와 관련 타입들은 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)
|
보유한 함수 객체의 결과의 보수를 반환하는 함수 객체를 생성
(함수 템플릿) |