使用哪种类型可调用 std::bind
Which type to use for callable to std::bind
在一个函数中,我需要将一个可调用对象作为参数传递给 std::bind。
我应该使用什么是正确的 type/template?
void foo(std::function<void(KnownType)> function, WhatShouldThisBe target)
{
std::bind(function, target);
}
预期用途将是:
std::shared_ptr<SomeType> bar = std::make_shared<SomeType>();
foo(&SomeType::function, bar);
类似
template <class T>
void foo(std::function<void(KnownType)> function, T&& target)
{
std::bind(function, std::forward<T>(target));
}
在一个函数中,我需要将一个可调用对象作为参数传递给 std::bind。 我应该使用什么是正确的 type/template?
void foo(std::function<void(KnownType)> function, WhatShouldThisBe target)
{
std::bind(function, target);
}
预期用途将是:
std::shared_ptr<SomeType> bar = std::make_shared<SomeType>();
foo(&SomeType::function, bar);
类似
template <class T>
void foo(std::function<void(KnownType)> function, T&& target)
{
std::bind(function, std::forward<T>(target));
}