std::mem_fn
은 핸드 롤 랩퍼 기능이 수행 할 수없는 사용 사례가 있습니다.std :: mem_fn의 불완전 성이 핸드 롤 기능과 비교
#include <functional>
struct A
{
};
struct B
{
B(A); // implicit conversion from A to B
void foo() const;
};
auto foo1 = std::mem_fn(&B::foo); // std::mem_fn
void foo2(const B& b) { b.foo(); } // hand-rolled wrapper
int main()
{
A a;
foo1(a); // doesn't work
foo2(a); // works fine
}
foo1은 호출에 대한 컴파일러 오류가 (GCC 4.8) 다음이다 : 그것은 래퍼 기능이 방법의 수업이 아닌 무언가에 사용하지만, 그것에 유형 암시 적으로 변환 할 때 온다 :
In file included from test.cpp:1:0:
functional: In instantiation of '_Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)const>::_M_call(_Tp&, const volatile void*, _ArgTypes ...) const [with _Tp = A; _Res = void; _Class = B; _ArgTypes = {}]':
functional:608:42: required from '_Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)const>::operator()(_Tp&, _ArgTypes ...) const [with _Tp = A; _Res = void; _Class = B; _ArgTypes = {}]'
test.cpp:21:11: required from here
functional:586:13: error: no match for 'operator*' (operand type is 'A')
{ return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
^
은이 유스 케이스는 손으로 압연 래퍼 않는 것처럼 작동하는 방식으로
std::mem_fn
을 구현하는 것이 가능했을 것이다?