为什么std :: shuffle方法在C ++ 14中被弃用? [英] Why are std::shuffle methods being deprecated in C++14?
问题描述
根据 cppreference.com 参考网站 std :: shufle ,以下方法在c ++ 14中已被弃用:
According to the cppreference.com reference site on std::shufle, the following method is being deprecated in c++14:
template< class RandomIt >
void random_shuffle( RandomIt first, RandomIt last );
为什么我们不能再传递第三个参数, >
Why will we no longer be able to call the following function without passing a third parameter?
std::random_shuffle(v.begin(),v.end()); //no longer valid in c++14
它不像一个不同的函数减速具有默认参数集。这背后的原因是什么?
It doesn't appear as though a different function deceleration has a default parameter set. What is the reason behind this? Was there some kind of alternative added?
推荐答案
std :: random_shuffle
可以使用随机
C系列函数。这些函数对种子和其他状态使用全局状态。
std::random_shuffle
may make use, under the hood, of random
C family of functions. These functions use global state for seeds and other state.
所以它被弃用,因为 shuffle
会做同样的,但更好。也就是说,它使用来自C ++ 11的不使用全局状态的新的< random>
头,但是它自己的对象使用生成器,设备和分布。
So it is being deprecated because shuffle
will do the same, but better. Namely, it uses the new <random>
header from C++11 that doesn't use global state, but its own objects making use of generators, devices and distributions.
这篇关于为什么std :: shuffle方法在C ++ 14中被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!