我正在使用GCC 4.6.3并尝试使用以下代码生成随机数:
#include <random>
#include <functional>
int main()
{
std::mt19937 rng_engine;
printf("With bind\n");
for(int i = 0; i < 5; ++i) {
std::uniform_real_distribution<double> dist(0.0, 1.0);
auto rng = std::bind(dist, rng_engine);
printf("%g\n", rng());
}
printf("Without bind\n");
for(int i = 0; i < 5; ++i) {
std::uniform_real_distribution<double> dist(0.0, 1.0);
printf("%g\n", dist(rng_engine));
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期望两种方法都能生成5个随机数的序列.相反,这是我实际得到的:
With bind
0.135477
0.135477
0.135477
0.135477
0.135477
Without bind
0.135477
0.835009
0.968868
0.221034
0.308167
Run Code Online (Sandbox Code Playgroud)
这是GCC的错误吗?或者是与std :: bind有关的一些微妙问题?如果是这样,你能对结果有所了解吗?
谢谢.
我正在设置一个包含某种集合类型值的Dictionary,如下所示:
IDictionary<string, ICollection<decimal>> goodPrices =
new Dictionary<string, List<decimal>>();
Run Code Online (Sandbox Code Playgroud)
但是,这行代码导致编译错误,无法将右侧隐式转换为左侧.显然,以下行不会产生错误:
IDictionary<string, List<decimal>> goodPrices =
new Dictionary<string, List<decimal>>();
Run Code Online (Sandbox Code Playgroud)
那么,在不暴露集合的底层实现的情况下,将"goodPrices"声明为一组字符串集合对的正确方法是什么?