functional_copyable_function
functional_copyable_function (복사 가능한 함수 래퍼)
std::copyable_function은 다목적 다형성 함수 래퍼예요. 복사 생성 가능한 호출 가능 객체를 저장하고 호출할 수 있으며, 함수 포인터, 람다 표현식, 바인드 표현식, 멤버 함수 포인터 등을 대상으로 삼을 수 있어요. std::function과 달리 빈 std::copyable_function을 호출하면 정의되지 않은 동작이 발생한다는 점을 유의해야 해요.
출처: cppreference
본문
<functional> 헤더에 정의되어 있어요.
| 정의 | ||
|---|---|---|
template < class ... > class copyable_function ; // not defined |
(1) | (since C++26) |
template < class R , class ... Args > class copyable_function < R ( Args ...) > ;template < class R , class ... Args > class copyable_function < R ( Args ...) noexcept > ;template < class R , class ... Args > class copyable_function < R ( Args ...) &> ;template < class R , class ... Args > class copyable_function < R ( Args ...) & noexcept > ;template < class R , class ... Args > class copyable_function < R ( Args ...) &&> ;template < class R , class ... Args > class copyable_function < R ( Args ...) && noexcept > ;template < class R , class ... Args > class copyable_function < R ( Args ...) const > ;template < class R , class ... Args > class copyable_function < R ( Args ...) const noexcept > ;template < class R , class ... Args > class copyable_function < R ( Args ...) const &> ;template < class R , class ... Args > class copyable_function < R ( Args ...) const & noexcept > ;template < class R , class ... Args > class copyable_function < R ( Args ...) const &&> ;template < class R , class ... Args > class copyable_function < R ( Args ...) const && noexcept > ; |
(2) | (since C++26) |
클래스 템플릿 std::copyable_function은 일반적인 목적의 다형성 함수 래퍼예요. std::copyable_function 객체는 CopyConstructible 요구 사항을 만족하는 모든 호출 가능 대상을 저장하고 호출할 수 있어요. 여기에는 함수, 람다 표현식, 바인드 표현식, 다른 함수 객체뿐만 아니라 멤버 함수 포인터와 멤버 객체 포인터도 포함돼요.
저장된 호출 가능 객체를 std::copyable_function의 대상(target)이라고 불러요. std::copyable_function에 대상이 없으면 비어 있다(empty)고 해요. std::function과 달리 빈 std::copyable_function을 호출하면 정의되지 않은 동작이 발생해요.
std::copyable_function은 템플릿 매개변수에 제공된 cv 한정자(volatile 제외), ref 한정자, 그리고 noexcept 지정자의 모든 가능한 조합을 지원해요. 이러한 한정자와 지정자는 operator()에 추가돼요.
std::copyable_function은 CopyConstructible과 CopyAssignable 요구 사항을 만족해요.
멤버 타입
| 타입 | 정의 |
|---|---|
result_type |
R |
멤버 함수
| 멤버 함수 | 설명 |
|---|---|
| (constructor) | 새로운 std::copyable_function 객체를 생성해요 (공개 멤버 함수) |
| (destructor) | std::copyable_function 객체를 소멸해요 (공개 멤버 함수) |
operator= |
대상을 교체하거나 파괴해요 (공개 멤버 함수) |
swap |
두 std::copyable_function 객체의 대상을 교환해요 (공개 멤버 함수) |
operator bool |
std::copyable_function에 대상이 있는지 확인해요 (공개 멤버 함수) |
operator() |
대상을 호출해요 (공개 멤버 함수) |
비멤버 함수
| 함수 | 설명 |
|---|---|
swap (std::copyable_function) (C++26) |
std::swap 알고리즘을 오버로드해요 (함수) |
operator== (C++26) |
std::copyable_function을 nullptr과 비교해요 (함수) |
참고 사항
구현은 작은 크기의 호출 가능 객체를 std::copyable_function 객체 내부에 저장할 수 있어요. 이러한 소형 객체 최적화는 함수 포인터와 std::reference_wrapper 특수화에 사실상 필수이며, std::is_nothrow_move_constructible_v<T>가 true인 타입 T에만 적용될 수 있어요.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_copyable_function |
202306L | (C++26) | std::copyable_function |
예제
| 이 섹션은 불완전해요. 이유: 예제 없음 |
|---|
같이 보기
| 함수 | 설명 |
|---|---|
function (C++11) |
복사 생성 가능한 모든 호출 가능 객체의 복사 가능 래퍼 (클래스 템플릿) |
move_only_function (C++23) |
주어진 호출 시그니처에서 한정자를 지원하는 모든 호출 가능 객체의 이동 전용 래퍼 (클래스 템플릿) |
function_ref (C++26) |
모든 호출 가능 객체의 비소유 래퍼 (클래스 템플릿) |