, :
template<class R, class... FArgs>
void test(std::function<R(FArgs...)> f)
{
}
int main() {
test(&SomeStruct::function);
}
easy_bind:
main.cpp: In function 'int main()':
main.cpp:63:31: error: no matching function for call to
'test(void (SomeStruct::*)(int, float, std::string))'
test(&SomeStruct::function);
main.cpp:63:31: note: candidate is:
main.cpp:49:10: note: template<class R, class ... FArgs>
void test(std::function<_Res(_ArgTypes ...)>)
void test(std::function<R(FArgs...)> f)
^
main.cpp:49:10: note: template argument deduction/substitution failed:
main.cpp:63:31: note: 'void (SomeStruct::*)(int, float, std::string)
{aka void (SomeStruct::*)(int, float, std::basic_string<char>)}'
is not derived from 'std::function<_Res(_ArgTypes ...)>'
test(&SomeStruct::function);
, std::function . - Functor.
, , , :
struct SomeStruct {
public:
int function(int x, float y, std::string str) {
std::cout << x << " " << y << " " << str << std::endl;
return 42;
}
};
template <typename Ret, typename Struct, typename ...Args>
std::function<Ret (Struct*,Args...)> proxycall(Ret (Struct::*mf)(Args...))
{
return std::function<Ret (Struct*,Args...)>(mf);
}
int main() {
auto func3 = fx::easy_bind(proxycall(&SomeStruct::function), new SomeStruct);
int ret = func3(5, 2.5, "Test3");
std::cout << ret << "\n";
return 0;
}
.
user1508519