如何发送通过绑定到函数/方法创建的函数对象?
How to send functional object, created by bind to function/method?
我为我的随机化需求创建了一个功能对象。
我只是不知道如何将它发送到没有模板的函数/方法。 有了他们,这很容易,只是
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
制造的
相关文章:
- 通过构造函数创建的所有对象都具有相同的向量
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- C++ :: 如何捕获由 void 函数创建的矩阵
- 通过零参数构造函数创建的 glm::mat4 应该包含哪些值?
- 用于基于成员字段或函数创建比较器的快捷方式
- std::使用类成员函数创建线程 - 最佳实践
- 为C++重载函数创建SWIG类型映射
- 使用成员函数创建std::函数不会编译
- 如何为返回特定类型的函数创建 SWIG 类型图
- 为具有多个参数的函数创建 SWIG 类型图的更简单方法?
- 通过另一个宏创建的函数创建所有列表的宏
- std::map<int, A> 运算符 [] 需要使用空构造函数创建 A
- 无法使用 CreateWindowEx 函数创建窗口
- c++ 从成员函数创建新线程并移动对象和整个对象
- 无法使用 c++ 中的类成员函数创建/写入文件
- 使用makeword函数创建错误e0109-表观呼叫的括号前表达式必须具有(指针到 - )函数类型
- 为 OpenMP 函数创建别名 ||部分禁用 openMP
- 稍后使用<Class>调用类构造函数创建 std::vector