Namespaces
Variants

std::function_ref::function_ref

From ko.cppreference.net
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐지됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
Swap 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
함수 객체
함수 호출
(C++17)(C++23)
항등 함수 객체
(C++20)
투명 연산자 래퍼
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

이전 바인더와 어댑터
(C++17까지*)
(C++17까지*)
(C++17까지*)
(C++17까지*)  
(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
(C++17까지*)(C++17까지*)
(C++17까지*)(C++17까지*)

(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
 
 
template< class F >
function_ref( F* f ) noexcept;
(1) (C++26부터)
template< class F >
function_ref( F&& f ) noexcept;
(2) (C++26부터)
template< auto f >
function_ref( std::nontype_t<f> ) noexcept;
(3) (C++26부터)
template< auto f, class U >
function_ref( std::nontype_t<f>, U&& obj ) noexcept;
(4) (C++26부터)
template< auto f, class T >
function_ref( std::nontype_t<f>, /*cv*/ T* obj ) noexcept;
(5) (C++26부터)
function_ref( const function_ref& other ) = default;
(6) (C++26부터)

새로운 std::function_ref을(를) 생성합니다.

1) bound-entity을(를) f(으)로 초기화하고, thunk-ptr을(를) 함수 thunk의 주소로 초기화합니다. f이 널 포인터인 경우 동작은 정의되지 않습니다.
  • 이 오버로드는 std::is_function_v<F>과(와) /*is-invocable-using*/<F>이(가) 모두 true인 경우에만 오버로드 해결에 참여합니다.
2) bound-entity을(를) std::addressof(f)(으)로 초기화하고, thunk-ptr을(를) 함수 thunk의 주소로 초기화합니다.
  • T을(를) std::remove_reference_t<F>이라고 합시다. 이 오버로드는 다음 조건이 모두 충족되는 경우에만 오버로드 해결에 참여합니다 :
    • std::remove_cvref_t<F>이(가) function_ref과(와) 같은 타입이 아니고,
    • std::is_member_pointer_v<T>이(가) false이며,
    • /*is-invocable-using*/</*cv*/ T&>이(가) true입니다.
3) bound-entity을(를) 지정되지 않은 객체에 대한 포인터 또는 널 포인터 값으로 초기화하고, thunk-ptr을(를) 함수 thunk의 주소로 초기화합니다.
  • F을(를) decltype(f)이라고 합시다. 이 오버로드는 /*is-invocable-using*/<F>이(가) true인 경우에만 오버로드 해결에 참여합니다.
  • f != nullptr이(가) false이고 std::is_pointer_v<F> || std::is_member_pointer_v<F>이(가) true인 경우 프로그램은 ill-formed입니다.
4) bound-entity을(를) std::addressof(obj)(으)로 초기화하고, thunk-ptr을(를) 함수 thunk의 주소로 초기화합니다.
  • T을(를) std::remove_reference_t<U>이라고 하고 F을(를) decltype(f)이라고 합시다. 이 오버로드는 다음 조건이 모두 충족되는 경우에만 오버로드 해결에 참여합니다 :
    • std::is_rvalue_reference_v<U&&>이(가) false이고,
    • /*is-invocable-using*/<F, /*cv*/ T&>이(가) true입니다.
  • f != nullptr이(가) false이고 std::is_pointer_v<F> || std::is_member_pointer_v<F>이(가) true인 경우 프로그램은 ill-formed입니다.
5) bound-entity을(를) obj(으)로 초기화하고, thunk-ptr을(를) 함수 thunk의 주소로 초기화합니다. obj이(가) 널 포인터이고 std::is_member_pointer_v<F>이(가) true인 경우 동작은 정의되지 않습니다.
  • F을(를) decltype(f)이라고 합시다. 이 오버로드는 /*is-invocable-using*/<F, /*cv*/ T*>이(가) true인 경우에만 오버로드 해결에 참여합니다.
  • f != nullptr이(가) false이고 std::is_pointer_v<F> || std::is_member_pointer_v<F>이(가) true인 경우 프로그램은 ill-formed입니다.
6) 기본화된 복사 생성자는 bound-entity과(와) thunk-ptr을(를) other에서 복사합니다.

함수 thunk의 주소는 thunk-ptr을(를) 초기화하는 데 사용되어 thunk(bound-entity, call-args...)에 대한 호출이 다음에 표현식-동등하도록 합니다:

오버로드 표현식-동등
(1,3) std::invoke_r<R>(f, call-args...)
(2) std::invoke_r<R>(static_cast<cvT&>(f), call-args...)
(4) std::invoke_r<R>(f, static_cast<cvT&>(obj), call-args...)
(5) std::invoke_r<R>(f, obj, call-args...)

/*is-invocable-using*/<T...>은(는) 다음 경우에만 true입니다:

  • std::is_nothrow_invocable_r_v<R, T..., Args...>은(는) true입니다. 만약 noex이(가) true이면, 또는
  • std::is_invocable_r_v<R, T..., Args...>은(는) true
입니다.

매개변수

other - 복사할 다른 function_ref
f - 래핑할 함수 또는 Callable 객체
obj - 바인딩할 객체 또는 포인터

예제

참고 항목

새로운 std::move_only_function 객체를 생성함
( std::move_only_function 의 public 멤버 함수)