如何发送通过绑定到函数/方法创建的函数对象?

How to send functional object, created by bind to function/method?

本文关键字:函数 创建 方法 对象 绑定 何发送      更新时间:2023-10-16

我为我的随机化需求创建了一个功能对象。

我只是不知道如何将它发送到没有模板的函数/方法。 有了他们,这很容易,只是

template <typename T>
void FooTemplate (T rand)
{
int b = rand(); // OK
}
void foo (... ?)
{
int a = rand(); // how to send generator to function?
}
int main(int argc, char* argv[])
{
auto rand = std::bind(std::uniform_int_distribution<uint32_t>{20, 30}, std::default_random_engine{ std::random_device()() });
return 0;
}
void foo(std::function<int()> rand) {...}

std::function<int()>将包装任何可调用的,包括由std::bind制造的