std::reference_wrapper<T>:: operator()
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
reference_wrapper::operator()
|
||||
| Non-member functions | ||||
|
(C++26)
(C++26)
|
||||
| Deduction guides (C++17) | ||||
| Helper classes | ||||
|
template
<
class
...
ArgTypes
>
typename
std::
result_of
<
T
&
(
ArgTypes
&&
...
)
>
::
type
|
(C++11부터)
(C++17까지) |
|
|
template
<
class
...
ArgTypes
>
std::
invoke_result_t
<
T
&
, ArgTypes...
>
|
(C++17부터)
(C++20부터 constexpr) |
|
저장된 참조가 가리키는
Callable
객체를 마치
INVOKE
(
get()
,
std::
forward
<
ArgTypes
>
(
args
)
...
)
와 같이 호출합니다. 이 함수는 저장된 참조가
Callable
객체를 가리킬 때만 사용 가능합니다.
T
는 완전한 타입이어야 합니다.
목차 |
매개변수
| args | - | 호출된 함수에 전달할 인수 |
반환값
호출된 함수의 반환 값.
예외
|
구현 정의 예외를 throw할 수 있습니다. |
(since C++11)
(until C++17) |
|
noexcept
명세:
noexcept
(
std::
is_nothrow_invocable_v
<
T
&
, ArgTypes...
>
)
|
(since C++17) |
예제
#include <functional> #include <iostream> void f1() { std::cout << "reference to function called\n"; } void f2(int n) { std::cout << "bind expression called with " << n << " as the argument\n"; } int main() { std::reference_wrapper<void()> ref1 = std::ref(f1); ref1(); auto b = std::bind(f2, std::placeholders::_1); auto ref2 = std::ref(b); ref2(7); auto c = []{ std::cout << "lambda function called\n"; }; auto ref3 = std::ref(c); ref3(); }
출력:
reference to function called bind expression called with 7 as the argument lambda function called
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 3764 | C++17 | operator ( ) is not noexcept | propagate noexcept |
참고 항목
|
저장된 참조에 접근
(public member function) |