2011-01-22 3 views
1

bind1st(mem_fun(&my_class::f), this) 펑터를 for_each으로 전달하고 싶습니다.자동으로 bind1st의 유형을 추론합니다 (mem_fun (& my_class :: f), this)?

(the type I am looking for) meaningful_name = bind1st(mem_fun(&my_class::f), this); 

for_each(v.begin(), v.end(), meaningful_name); 

펑의 유형을 추론 할 수있는 간단한 방법이 있나요 : 불행하게도 내가이 같은 이상을 할수있게 이름을주고 싶습니다 그래서 읽기 매우 어렵다? (나는 mem_fun이 이런 이유로 정확하게 많은 고통을 덜어 준다는 것을 안다.)

답변

4

이는 인수 및 my_class : f의 반환 유형에 따라 다릅니다.

auto meaningful_name = bind1st(mem_fun(&my_class::f), this); 
+0

을 거의 : 그것이 있어야'mem_fun1_t'하지 함수가 다음

T my_class::f(A arg) 

경우 당신은 이런 종류의 일이 + +0 C와 더 좋은 것

binder1st<mem_fun1_t<T,my_class,A> > meaningful_name = bind1st(mem_fun(&my_class::f), this); 

필요 'mem_fun1_1'. –

+0

@ 아담 : Thx, fixed – JoergB

2

아니오 간단한 방법이 없다. 형식 이름은 오히려 길어서 읽을 수 없게됩니다. 부스트를 사용하는 경우 boost::bind을 사용하고 로컬 필요없이 읽을 수 있기 때문에 BOOST_AUTO을 사용할 필요가 없습니다.

for_each(v.begin(), v.end(), boost::bind(&my_class::f, this));