functional_mem_fun_ref
functional_mem_fun_ref (멤버 함수 참조 래퍼 생성)
이 함수는 멤버 함수에 대한 래퍼 객체를 생성해요. 템플릿 인자에서 대상 타입을 추론하며, 생성된 래퍼 객체는 operator()의 첫 번째 매개변수로 T 타입 객체에 대한 참조를 기대해요. 이 함수와 관련 타입들은 C++11에서 더 이상 사용되지 않게 되었고, C++17에서 제거되었어요. 더 일반적인 std::mem_fn과 std::bind가 멤버 함수로부터 호출 가능한 어댑터 호환 함수 객체를 만들어 주므로, 그들을 사용하는 것이 좋아요.
출처: cppreference
본문
Defined in header <functional> |
||
|---|---|---|
template < class Res , class T > std :: mem_fun_ref_t < Res , T > mem_fun_ref ( Res ( T ::* f )() ); |
(1) | (deprecated in C++11) (removed in C++17) |
template < class Res , class T > std :: const_mem_fun_ref_t < Res , T > mem_fun_ref ( Res ( T ::* f )() const ); |
(1) | (deprecated in C++11) (removed in C++17) |
template < class Res , class T , class Arg > std :: mem_fun1_ref_t < Res , T , Arg > mem_fun_ref ( Res ( T ::* f )( Arg ) ); |
(2) | (deprecated in C++11) (removed in C++17) |
template < class Res , class T , class Arg > std :: const_mem_fun1_ref_t < Res , T , Arg > mem_fun_ref ( Res ( T ::* f )( Arg ) const ); |
(2) | (deprecated in C++11) (removed in C++17) |
Parameters
| f | - | 래퍼를 생성할 멤버 함수에 대한 포인터 |
Return value
f를 감싸는 함수 객체를 반환해요.
Exceptions
구현 정의 예외를 던질 수 있어요.
Notes
std::mem_fun과 std::mem_fun_ref의 차이는 전자가 객체에 대한 포인터를 기대하는 함수 래퍼를 생성하는 반면, 후자는 참조를 기대한다는 점이에요.
Example
std::mem_fun_ref를 사용해서 std::string의 멤버 함수 size()를 바인딩해요.
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> v = {"once", "upon", "a", "time"};
std::transform(v.cbegin(), v.cend(),
std::ostream_iterator<std::size_t>(std::cout, " "),
std::mem_fun_ref(&std::string::size));
}
출력:
4 4 1 4
See also
mem_fun (C++11에서 더 이상 사용되지 않음) (C++17에서 제거됨) |
객체에 대한 포인터로 호출할 수 있는 멤버 함수 포인터로부터 래퍼를 생성해요 (함수 템플릿) [edit] |
|---|