Namespaces
Variants

std:: mem_fun_ref

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

mem_fun_ref
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
헤더 파일에 정의됨 <functional>
template < class Res, class T >
std:: mem_fun_ref_t < Res,T > mem_fun_ref ( Res ( T :: * f ) ( ) ) ;
(1) (C++11부터 사용 중단됨)
(C++17에서 제거됨)
template < class Res, class T >
std:: const_mem_fun_ref_t < Res,T > mem_fun_ref ( Res ( T :: * f ) ( ) const ) ;
(1) (C++11부터 사용 중단됨)
(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) (C++11부터 사용 중단됨)
(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) (C++11부터 사용 중단됨)
(C++17에서 제거됨)

멤버 함수 래퍼 객체를 생성하며, 템플릿 인자로부터 대상 타입을 추론합니다. 래퍼 객체는 첫 번째 매개변수로 T 타입 객체에 대한 참조를 operator ( ) 에 전달할 것을 기대합니다.

1) 효과적으로 std:: mem_fun_ref_t < S,T > ( f ) 또는 std:: const_mem_fun_ref_t < S,T > ( f ) 를 호출합니다.
2) 효과적으로 std:: mem_fun1_ref_t < S,T > ( f ) 또는 std:: const_mem_fun1_ref_t < S,T > ( f ) 를 호출합니다.

이 함수와 관련된 타입들은 C++11에서 사용 중단(deprecated)되었으며 C++17에서 제거되었습니다. 더 일반적인 std::mem_fn std::bind 으로 대체되었으며, 이 둘 모두 멤버 함수로부터 호출 가능한 어댑터 호환 함수 객체를 생성합니다.

목차

매개변수

f - 래퍼를 생성할 멤버 함수에 대한 포인터

반환값

f 를 감싸는 함수 객체.

예외

구현에서 정의된 예외를 던질 수 있습니다.

참고 사항

std:: mem_fun std :: mem_fun_ref 의 차이점은 전자가 객체에 대한 포인터를 기대하는 함수 래퍼를 생성하는 반면, 후자는 참조를 기대한다는 것입니다.

예제

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

참고 항목

(C++11에서 사용 중단됨) (C++17에서 제거됨)
객체 포인터로 호출 가능한 멤버 함수 포인터로부터 래퍼를 생성함
(함수 템플릿)